aboutsummaryrefslogtreecommitdiff
path: root/drivers/usb/dwc3/ep0.c
AgeCommit message (Collapse)AuthorFilesLines
2016-02-17usb: dwc3: Fix assignment of EP transfer resourcesJohn Youn1-5/+0
The assignement of EP transfer resources was not handled properly in the dwc3 driver. Commit aebda6187181 ("usb: dwc3: Reset the transfer resource index on SET_INTERFACE") previously fixed one aspect of this where resources may be exhausted with multiple calls to SET_INTERFACE. However, it introduced an issue where composite devices with multiple interfaces can be assigned the same transfer resources for different endpoints. This patch solves both issues. The assignment of transfer resources cannot perfectly follow the data book due to the fact that the controller driver does not have all knowledge of the configuration in advance. It is given this information piecemeal by the composite gadget framework after every SET_CONFIGURATION and SET_INTERFACE. Trying to follow the databook programming model in this scenario can cause errors. For two reasons: 1) The databook says to do DEPSTARTCFG for every SET_CONFIGURATION and SET_INTERFACE (8.1.5). This is incorrect in the scenario of multiple interfaces. 2) The databook does not mention doing more DEPXFERCFG for new endpoint on alt setting (8.1.6). The following simplified method is used instead: All hardware endpoints can be assigned a transfer resource and this setting will stay persistent until either a core reset or hibernation. So whenever we do a DEPSTARTCFG(0) we can go ahead and do DEPXFERCFG for every hardware endpoint as well. We are guaranteed that there are as many transfer resources as endpoints. This patch triggers off of the calling dwc3_gadget_start_config() for EP0-out, which always happens first, and which should only happen in one of the above conditions. Fixes: aebda6187181 ("usb: dwc3: Reset the transfer resource index on SET_INTERFACE") Cc: <[email protected]> # v3.2+ Reported-by: Ravi Babu <[email protected]> Signed-off-by: John Youn <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2015-12-15usb: dwc3: ep0: fix setup_packet_pending initializationFelipe Balbi1-3/+5
It just ocurred to me that dwc3 already gives a really hint of when a setup packet is pending and that's the SETUP_PENDING TRB Status for EP0 IRQs. Fix setup_packet_pending initialization based on that. While at that, also make sure the comment in gadget.c matches what code is doing. Signed-off-by: Felipe Balbi <[email protected]>
2015-12-15usb: dwc3: ep0: purge dev_dbg() callsFelipe Balbi1-2/+2
The last few dev_dbg() messages are converted to tracepoints and we can finally ignore dev_dbg() messages during debug sessions. Signed-off-by: Felipe Balbi <[email protected]>
2015-07-30usb: dwc3: ep0: handle non maxpacket aligned transfers > 512Kishon Vijay Abraham I1-14/+28
Use chained TRB mechanism to handle non maxpacket aligned transfers greater than bounce buffer size. With this the first TRB will be programmed to receive 'ALIGN(ur->length - maxp, maxp)' data and the second TRB will be programmed to receive the remaining data using bounce buffer. Signed-off-by: Kishon Vijay Abraham I <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2015-07-30usb: dwc3: ep0: Add chained TRB supportKishon Vijay Abraham I1-3/+13
Add chained TRB support to ep0. Now TRB's can be chained just by invoking _dwc3_ep0_start_trans_ with 'chain' parameter set to true. Signed-off-by: Kishon Vijay Abraham I <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2015-07-30usb: dwc3; ep0: Modify _dwc3_ep0_start_trans_ API to take 'chain' parameterKishon Vijay Abraham I1-7/+8
No functional change. Added a new parameter in _dwc3_ep0_start_trans_ to indicate whether the TRB is a chained TRB or last TRB. This is in preparation for adding chained TRB support for ep0. Signed-off-by: Kishon Vijay Abraham I <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2015-07-30usb: dwc3: ep0: preparation for handling non maxpacket aligned transfers > 512Kishon Vijay Abraham I1-8/+17
No functional change. This is in preparation for handling non maxpacket aligned transfers greater than bounce buffer size. This is basically to avoid code duplication when using chained TRB transfers to handle non maxpacket aligned transfers greater than bounce buffer size. Signed-off-by: Kishon Vijay Abraham I <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2015-07-30usb: dwc3: ep0: use _roundup_ to calculate the transfer sizeKishon Vijay Abraham I1-3/+1
No functional change. Used _roundup_ macro to calculate the transfer size aligned to maxpacket in dwc3_ep0_complete_data. It also makes it similar to how transfer size is calculated in __dwc3_ep0_do_control_data. Signed-off-by: Kishon Vijay Abraham I <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2015-07-30usb: dwc3: ep0: Fix mem corruption on OUT transfers of more than 512 bytesKishon Vijay Abraham I1-2/+10
DWC3 uses bounce buffer to handle non max packet aligned OUT transfers and the size of bounce buffer is 512 bytes. However if the host initiates OUT transfers of size more than 512 bytes (and non max packet aligned), the driver throws a WARN dump but still programs the TRB to receive more than 512 bytes. This will cause bounce buffer to overflow and corrupt the adjacent memory locations which can be fatal. Fix it by programming the TRB to receive a maximum of DWC3_EP0_BOUNCE_SIZE (512) bytes. Cc: <[email protected]> # 3.4+ Signed-off-by: Kishon Vijay Abraham I <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2015-07-22usb: dwc3: Reset the transfer resource index on SET_INTERFACEJohn Youn1-0/+4
This fixes an issue introduced in commit b23c843992b6 (usb: dwc3: gadget: fix DEPSTARTCFG for non-EP0 EPs) that made sure we would only use DEPSTARTCFG once per SetConfig. The trick is that we should use one DEPSTARTCFG per SetConfig *OR* SetInterface. SetInterface was completely missed from the original patch. This problem became aparent after commit 76e838c9f776 (usb: dwc3: gadget: return error if command sent to DEPCMD register fails) added checking of the return status of device endpoint commands. 'Set Endpoint Transfer Resource' command was caught failing occasionally. This is because the Transfer Resource Index was not getting reset during a SET_INTERFACE request. Finally, to fix the issue, was we have to do is make sure that our start_config_issued flag gets reset whenever we receive a SetInterface request. To verify the problem (and its fix), all we have to do is run test 9 from testusb with 'testusb -t 9 -s 2048 -a -c 5000'. Tested-by: Huang Rui <[email protected]> Tested-by: Subbaraya Sundeep Bhatta <[email protected]> Fixes: b23c843992b6 (usb: dwc3: gadget: fix DEPSTARTCFG for non-EP0 EPs) Cc: <[email protected]> # v3.2+ Signed-off-by: John Youn <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2015-01-29usb: dwc3: gadget: use common is_selfpoweredPeter Chen1-1/+1
Delete private selfpowered variable, and use common one. Signed-off-by: Peter Chen <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2014-11-30Merge 3.18-rc7 into usb-nextGreg Kroah-Hartman1-4/+4
We need the xhci fixes here and this resolves a merge issue with drivers/usb/dwc3/ep0.c Signed-off-by: Greg Kroah-Hartman <[email protected]>
2014-11-10usb: dwc3: ep0: fix for dead codeFelipe Balbi1-4/+4
commit 6856d30 (usb: dwc3: ep0: return early on NULL requests) tried to fix a minor corner case where we could dereference a NULL pointer but it also ended up introducing some dead code. Unfortunately, that dead code, if reached, could end up starving the endpoint request list because a request would never be given back when it should. Fix this by moving the check for empty request list before its first use. Reported-by: Dave Jones <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2014-11-05usb: dwc3: ep0: remove unnecessary break after returnJingoo Han1-2/+0
Fix the following checkpatch warning. WARNING: break is not useful after a goto or return Signed-off-by: Jingoo Han <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2014-11-03usb: dwc3: ep0: trace ep0 TRBs tooFelipe Balbi1-0/+6
Add TRB tracepoints for ep0 TRBs as that might help finding bugs with ep0 handling. Signed-off-by: Felipe Balbi <[email protected]>
2014-11-03usb: dwc3: trace: remove unnecessary newline characterFelipe Balbi1-9/+9
tracing infrastructure already adds those for us. Signed-off-by: Felipe Balbi <[email protected]>
2014-10-23usb: dwc3: ep0: fix Data Phase for transfer sizes aligned to wMaxPacketSizeFelipe Balbi1-6/+13
According to Section 8.5.3.2 of the USB 2.0 specification, a USB device must terminate a Data Phase with either a short packet or a ZLP (if the previous transfer was a multiple of wMaxPacketSize). For reference, here's what the USB 2.0 specification, section 8.5.3.2 says: " 8.5.3.2 Variable-length Data Stage A control pipe may have a variable-length data phase in which the host requests more data than is contained in the specified data structure. When all of the data structure is returned to the host, the function should indicate that the Data stage is ended by returning a packet that is shorter than the MaxPacketSize for the pipe. If the data structure is an exact multiple of wMaxPacketSize for the pipe, the function will return a zero-length packet to indicate the end of the Data stage. " Signed-off-by: Felipe Balbi <[email protected]>
2014-10-20usb: dwc3: ep0: return early on NULL requestsFelipe Balbi1-3/+6
if our list of requests is empty, return early. There's really nothing to be done in case our request list is empty anyway because the only situation where we our list is empty, is when we're transferring ZLPs. Signed-off-by: Felipe Balbi <[email protected]>
2014-10-20usb: dwc3: gadget: fix set_halt() bug with pending transfersFelipe Balbi1-2/+2
According to our Gadget Framework API documentation, ->set_halt() *must* return -EAGAIN if we have pending transfers (on either direction) or FIFO isn't empty (on TX endpoints). Fix this bug so that the mass storage gadget can be used without stall=0 parameter. This patch should be backported to all kernels since v3.2. Cc: <[email protected]> # v3.2+ Suggested-by: Alan Stern <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2014-10-20usb: dwc3: ep0: hold our lock in dwc3_gadget_ep0_set_haltFelipe Balbi1-1/+15
dwc3_gadget_ep0_set_halt() will be called without locks held in some cases, so we must hold the lock on our own. While at that, also add a version without locks to be called in certain conditions. Signed-off-by: Felipe Balbi <[email protected]>
2014-09-05usb: dwc3: add tracepoints to aid debuggingFelipe Balbi1-28/+36
When we're debugging hard-to-reproduce and time-sensitive use cases, printk() poses too much overhead. That's when the kernel's tracing infrastructure comes into play. This patch implements a few initial tracepoints for the dwc3 driver. More traces can be added as necessary in order to ease the task of debugging dwc3. Reviewed-by: Paul Zimmerman <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2014-09-05usb: dwc3: move all string helper functions to debug.hFelipe Balbi1-0/+1
Those functions are only using within debugging messages, grouping them into debug.h makes sense. While at that, also add missing multiple inclusion guard. Signed-off-by: Felipe Balbi <[email protected]>
2013-11-25usb: dwc3: fix implementation of endpoint wedgeAlan Stern1-0/+2
The dwc3 UDC driver doesn't implement endpoint wedging correctly. When an endpoint is wedged, the gadget driver should be allowed to clear the wedge by calling usb_ep_clear_halt(). Only the host is prevented from resetting the endpoint. This patch fixes the implementation. Signed-off-by: Alan Stern <[email protected]> Tested-by: Pratyush Anand <[email protected]> Cc: <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2013-10-11usb: Remove unnecessary semicolonsJoe Perches1-3/+3
These aren't necessary after switch and if blocks. Signed-off-by: Joe Perches <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2013-07-29usb: dwc3: ep0: don't change to configured state too earlyFelipe Balbi1-2/+11
before changing to configured state, we need to wait until gadget driver has had a chance to process the request. In case of USB_GADGET_DELAYED_STATUS, that means we need to defer usb_gadget_set_state() until the upcoming usb_ep_queue(). Reported-by: Alan Stern <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2013-07-29usb: dwc3: ep0: only change to ADDRESS if set_config() succeedsFelipe Balbi1-1/+1
In case we're switching back to USB_STATE_ADDRESS from USB_STATE_CONFIGURED (if host sends a set configuration command for configuration zero), we should only switch if the request is successfully processed by the gadget driver. Reported-by: Alan Stern <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2013-07-29usb: dwc3: switch to GPL v2 onlyFelipe Balbi1-27/+7
This is a Linux-only driver which makes use of GPL-only symbols. It makes no sense to maintain Dual BSD/GPL licensing for this driver. Considering that the amount of work to use this driver in any different operating system would likely be as large as developing the driver from scratch and considering that we depend on GPL-only symbols, we will switch over to a GPL v2-only license. Cc: Anton Tikhomirov <[email protected]> Acked-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2013-03-18usb: dwc3: remove our homebrew state mechanismFelipe Balbi1-17/+17
We can reuse the generic implementation via our struct usb_gadget. Signed-off-by: Felipe Balbi <[email protected]>
2013-03-18usb: dwc3: gadget: implement gadget state trackingFelipe Balbi1-3/+12
make use of the previously introduced gadget->state field. Signed-off-by: Felipe Balbi <[email protected]>
2013-03-08usb: dwc3: ep0: fix sparc64 buildAndrew Morton1-3/+4
drivers/usb/dwc3/ep0.c: In function `__dwc3_ep0_do_control_data': drivers/usb/dwc3/ep0.c:905: error: `typeof' applied to a bit-field Looks like a gcc-3.4.5/sparc64 bug. Cc: Greg Kroah-Hartman <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2012-09-16Merge 3.6-rc6 into usb-nextGreg Kroah-Hartman1-1/+0
This resolves the merge problems with: drivers/usb/dwc3/gadget.c drivers/usb/musb/tusb6010.c that had been seen in linux-next. Signed-off-by: Greg Kroah-Hartman <[email protected]>
2012-09-06usb: dwc3: ep0: correct cache sync issue in case of ep0_bouncedPratyush Anand1-1/+0
In case of ep0 out, if length is not aligned to maxpacket size then we use dwc->ep_bounce_addr for dma transfer and not request->dma. Since, we have alreday done memcpy from dwc->ep0_bounce to request->buf, so we do not need to issue cache sync function. In fact, cache sync function will bring wrong data in request->buf from request->dma in this scenario. So, cache sync function must not be executed in case of ep0 bounced. Cc: <[email protected]> # v3.4 v3.5 Signed-off-by: Pratyush Anand <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2012-08-03usb: dwc3: ep0: make sure to reinitilize ep1 on STALLFelipe Balbi1-1/+6
When issuing SetStall on ep0, we must make sure to reinitialize all flags on physical ep1 too. Signed-off-by: Felipe Balbi <[email protected]>
2012-08-03usb: dwc3: ep0: fix status phase delayed status directionFelipe Balbi1-1/+4
commit 68d3e66 (usb: dwc3: ep0: fix for possible early delayed_status) added handling for early delayed status, but the current code only works because so far delayed status will always be on the IN direction. This patch makes the code more robust by making sure that we can handle all directions properly. Signed-off-by: Felipe Balbi <[email protected]>
2012-08-03usb: dwc3: ep0: drop XferNotReady(DATA) supportFelipe Balbi1-40/+27
Due to the late Silicon limitation found, we are now pre-starting DATA phase's TRBs. If, still, we get XferNotReady(DATA) we will ignore it unless we're getting it for the wrong direction. In that case we must keep the error case handling plus add a ENDTRANSFER command to forcefully end the Data TRB we started previously, then continue to SetStall and so on. Signed-off-by: Felipe Balbi <[email protected]>
2012-08-03usb: dwc3: ep0: move DATA phase away from on-demandFelipe Balbi1-0/+62
We uncovered a limitation of this core WRT to the Link Layer Compliance Suite's TD7.06. On that test, host will start a GetDescriptor(DEVICE) standard request, but it will do so only on the SETUP phase, meaning there will *NOT* be any DATA or STATUS phases. The idea of the test is to verify robustness of the IP WRT framing errors, so the test will send a sequence of different SETUP_DPs each with a different framing error and the Suite expects us to be able to receive all SETUP_DPs with no timeouts. This core, has the ability to tell us which phase the host is expecting before we start it. Whenever we receive a TP or DP when no transfers are cached on the internal IP's caches, the IP will generate a XferNotReady event with status informing us (in case of physical ep0/ep1) if it's related to DATA or STATUS phases - SETUP phase is expected to be prestarted. Because we're always waiting for XferNotReady events for DATA and STATUS phases, we will never be able to know that the Host wants to start another SETUP phase instead, which will render us "not compliant" with TD7.06. In order to "fix" the problem we must not rely on XferNotReady events for the DATA phase and try to always pre-start DATA transfers on physical endpoints 0 and 1. If host goes back to SETUP phase from DATA phase we will receive a XferComplete for that phase with TRB's status set to SETUP_PENDING, which is only useful for printing a debugging log as the core expects us to still go through to the STATUS phase, initiate a CONTROL_STATUS TRB just so it completes right away and, only then, we go back to the pending SETUP phase. SNPS has decided to modify the programming model of the core so that on-demand DATA phases will not be supported anymore. Note that this limitation does not affect 2-stage transfers, meaning that if TD7.06 would start a 2-stage transfer instead of a 3-stage transfer, we would receive a "fake" XferNotReady(STATUS) which would complete right after being initiated with SETUP_PENDING status. Other endpoints are also not affected, so we can still use on-demand transfers on Bulk/Isoc/Interrupt endpoints. Signed-off-by: Felipe Balbi <[email protected]>
2012-08-03usb: dwc3: ep0: ignore XferNotReady(STATUS) when we're not expecting itFelipe Balbi1-9/+3
Databook doesn't say we should stall if we get XferNotReady(STATUS) while we're expecting something else. Instead of stalling and restarting, tests have proven that ignoring the event is far more effective. This problem has been caught while rewriting ep0 handling in order we pass Link Layer TD7.6. Signed-off-by: Felipe Balbi <[email protected]>
2012-08-03usb: dwc3: ep0: drop dead codeFelipe Balbi1-49/+0
There's no such thing as XferNotReady(SETUP), we can safely drop all that code with no problems whatsoever. Signed-off-by: Felipe Balbi <[email protected]>
2012-08-03usb: dwc3: ep0: split the special cases on ep0_queueFelipe Balbi1-1/+11
We can return early from each if () branch and split the special cases for clarity. While at that also add a comment to the delayed_status case. Signed-off-by: Felipe Balbi <[email protected]>
2012-08-03usb: dwc3: ep0: drop unnecessary variableFelipe Balbi1-2/+1
When returning from ep0_queue, we have an unnecessary ret variable which is always zero. Remove it. Signed-off-by: Felipe Balbi <[email protected]>
2012-07-02usb: dwc3: enable ACCEPT{U1,U2}ENA when SetConfiguration receivedPratyush Anand1-0/+9
As per databook, ACCEPT{U1,U2}ENA bits should be set after receiving SetConfiguration Command. Signed-off-by: Pratyush Anand <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2012-07-02usb: dwc3: correct set_halt implementation for ep0Pratyush Anand1-0/+10
set_halt for ep0 is called to stall a deferred control responses by the gadget. We already have a function to stall default control endpoint. This patch points set_halt for ep0 to the already available function. Signed-off-by: Pratyush Anand <[email protected]> Signed-off-by: Michel Sanches <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
2012-06-25usb: dwc3: ep0: prevent starting transfers twice on ep0Felipe Balbi1-0/+1
In case we try to start an invalid test mode, we will call dwc3_ep0_stall_and_restart() but we will also call dwc3_ep0_out_start() which will start a second transfer on ep0. Let's prevent any problems by returning early in the error case. Signed-off-by: Felipe Balbi <[email protected]>
2012-06-25usb: dwc3: rename res_trans_idx to resource_indexFelipe Balbi1-2/+2
resource_index is more human readable. No functional changes. Signed-off-by: Felipe Balbi <[email protected]>
2012-06-03usb: dwc3: ep0: rename dwc3_ep0_complete_req to dwc3_ep0_complete_statusFelipe Balbi1-2/+2
That's a much more intuitive name as that function is only called at the completion of a Status Phase. It also matches dwc3_ep0_complete_data() for the completion of Data Phase. Signed-off-by: Felipe Balbi <[email protected]>
2012-06-03usb: dwc3: ep0: be careful with endianness on SetSEL commandFelipe Balbi1-2/+2
USB is always little endian, but this driver could run on non little endian cpus. Let's be carefull with that. Signed-off-by: Felipe Balbi <[email protected]>
2012-06-03usb: dwc3: ep0: simplify error handling on dwc3_ep0_inspect_setupFelipe Balbi1-7/+5
There's no need for returning early. Instead, we can call dwc3_ep0_stall_and_restart() conditionally. Signed-off-by: Felipe Balbi <[email protected]>
2012-06-03usb: dwc3: ep0: fix a typo in commentFelipe Balbi1-1/+1
s/has/have. No functional changes, just a typo fix on a code comment. Signed-off-by: Felipe Balbi <[email protected]>
2012-06-03usb: dwc3: ep0: align on function signatureFelipe Balbi1-6/+12
On our Transfer Not Ready handlers, only dwc3_ep0_do_control_status() had a different list of parameters. Align on the parameters in order to keep consistency. No functional changes. Signed-off-by: Felipe Balbi <[email protected]>
2012-06-03usb: dwc3: ep0: switch over to IS_ALIGNEDFelipe Balbi1-1/+1
IS_ALIGNED provides a much faster operation for checking proper size alignment then a modulo operation. Let's use it. Reported-by: Pratyush Anand <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>