Commit graph

170 commits

Author SHA1 Message Date
Felipe Balbi
2e3db06485 usb: dwc3: ep0: drop XferNotReady(DATA) support
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 <balbi@ti.com>
2012-08-03 09:28:26 +03:00
Felipe Balbi
fca8892ae5 usb: dwc3: ep0: move DATA phase away from on-demand
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 <balbi@ti.com>
2012-08-03 09:28:26 +03:00
Felipe Balbi
77fa6df82f usb: dwc3: ep0: ignore XferNotReady(STATUS) when we're not expecting it
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 <balbi@ti.com>
2012-08-03 09:28:25 +03:00
Felipe Balbi
4635d3f298 usb: dwc3: ep0: drop dead code
There's no such thing as XferNotReady(SETUP), we
can safely drop all that code with no problems
whatsoever.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-08-03 09:28:25 +03:00
Felipe Balbi
d9b33c605c usb: dwc3: ep0: split the special cases on ep0_queue
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 <balbi@ti.com>
2012-08-03 09:28:24 +03:00
Felipe Balbi
35f7569664 usb: dwc3: ep0: drop unnecessary variable
When returning from ep0_queue, we have an
unnecessary ret variable which is always
zero. Remove it.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-08-03 09:28:23 +03:00
Pratyush Anand
e274a31e29 usb: dwc3: enable ACCEPT{U1,U2}ENA when SetConfiguration received
As per databook, ACCEPT{U1,U2}ENA bits should be set after receiving
SetConfiguration Command.

Signed-off-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-07-02 10:03:55 +03:00
Pratyush Anand
08f0d96670 usb: dwc3: correct set_halt implementation for ep0
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 <pratyush.anand@st.com>
Signed-off-by: Michel Sanches <michel.sanches@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-07-02 10:02:07 +03:00
Felipe Balbi
5c81ababec usb: dwc3: ep0: prevent starting transfers twice on ep0
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 <balbi@ti.com>
2012-06-25 19:30:49 +03:00
Felipe Balbi
b4996a8631 usb: dwc3: rename res_trans_idx to resource_index
resource_index is more human readable. No
functional changes.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-25 14:00:45 +03:00
Felipe Balbi
85a781019b usb: dwc3: ep0: rename dwc3_ep0_complete_req to dwc3_ep0_complete_status
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 <balbi@ti.com>
2012-06-03 23:08:28 +03:00
Felipe Balbi
c8cf7af452 usb: dwc3: ep0: be careful with endianness on SetSEL command
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 <balbi@ti.com>
2012-06-03 23:08:27 +03:00
Felipe Balbi
ef21ede65e usb: dwc3: ep0: simplify error handling on dwc3_ep0_inspect_setup
There's no need for returning early. Instead,
we can call dwc3_ep0_stall_and_restart()
conditionally.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:27 +03:00
Felipe Balbi
33b84c2c06 usb: dwc3: ep0: fix a typo in comment
s/has/have. No functional changes, just
a typo fix on a code comment.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:20 +03:00
Felipe Balbi
788a23f496 usb: dwc3: ep0: align on function signature
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 <balbi@ti.com>
2012-06-03 23:08:19 +03:00
Felipe Balbi
c74c6d4a02 usb: dwc3: ep0: switch over to IS_ALIGNED
IS_ALIGNED provides a much faster operation for
checking proper size alignment then a modulo
operation. Let's use it.

Reported-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:19 +03:00
Felipe Balbi
a0807881af usb: dwc3: handle pending unaligned Control OUT data phase correctly
When DWC3_EP_PENDING_REQUEST flag is set for a Control OUT Data
phase transfer, we would be missing the proper handling for
unaligned OUT requests, thus hanging a transfer.

Since proper handling is already done on dwc3_ep0_do_control_data(),
we simply re-factor that function so it can be re-used from
__dwc3_gadget_ep0_queue().

Reported-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:18 +03:00
Felipe Balbi
4552a0ca61 usb: dwc3: fix a WARN and a comment
we're now have DWC3_EP0_BOUNCE_SIZE to tell
us the actual size of the bufer. Let's use that
instead of ep0 wMaxPacketSize.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-06-03 23:08:17 +03:00
Greg Kroah-Hartman
23063b378d usb: dwc3: patches for v3.5 merge window
This pull request contains one workaround for a Silicon
 Issue found on all RTL releases prior to 2.20a, which
 would cause a metastability state on Run/Stop bit.
 
 We also have some patches implementing a few extra Standard
 requests introduced by USB3 spec (Set SEL and Set Isoch Delay),
 as well as one patch, which has been pending for a long time,
 implementing LPM support.
 
 Last, but not least, we are splitting the host address space
 out of the dwc3 core driver otherwise xHCI won't be able to
 request_mem_region() its own address space. This patch is
 only needed because we are (as we should) re-using the xHCI
 driver, which is a completely separate module.
 
 Together with these three big changes, come a few extra preparatory
 patches which most move code around, define macros and so on, as
 well as a fix for Isochronous transfers which hasn't been triggered
 before.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.12 (GNU/Linux)
 
 iQIcBAABAgAGBQJPo7lXAAoJEIaOsuA1yqRESaIP/AgxZIfOAUbPx0GWLnhub3qr
 SxaUplweFc9q4KXRLn0kGdY9QArPR3bqW9g8KOTiRCBYRtjpACyMjibAUaAht81h
 +vLdPt87Slj2c14t1uguWFvgCUYQOCugkVvDIjRg9PCLIuTahm4cIBFqL3RJOHFf
 9WCd8JjH9ahr85ZtoCBk9B5bDNn71nS+Yh6/8+Ab90AE4vZ6t8Xx3+wLTHy2CBYQ
 UH1o61QZreAJ0J3OiUobjqrVbYwz6TM0dFYMjA6ko+OiPRhVOj8/C8aNl/U1whRm
 +7jjJiWO9aHp+Tu2OAQOBF6ydc3ZLBEiCl9RiE+O9MppmtOykzkTHFm1ZXatCEY7
 UUYOy43VXLNlHoz8nidNw6P25hAwwlSijzlyawpihKbIaE8le2MpE6I00AlciM2q
 BEo4LpluC8Rr6CUUr5W9dPZUexRlzxdAL5nQSJUnJgfEPphpP3x7dWTxUZBaWjq6
 akqjgGqVj1QKwMnqL4GILtRgdqWj6WYrw67fYVLHqj8QQla4cgXQ2sHp9/R0imvT
 nmjiL5ZiuIWWr965DgVHZwqIkdvMpSQb99a1xmptw8lFDGkVJDCssPDdEErbBMwy
 KmOSaqKeg/Yway05i+Pwo/NUKHQSZeiyuguzniMrF7iYFF1/2hVYRgfpH4V+95w/
 Xrnz4uH2YJGQGPddf87P
 =qgf/
 -----END PGP SIGNATURE-----

Merge tag 'dwc3-for-v3.5' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next

usb: dwc3: patches for v3.5 merge window

This pull request contains one workaround for a Silicon
Issue found on all RTL releases prior to 2.20a, which
would cause a metastability state on Run/Stop bit.

We also have some patches implementing a few extra Standard
requests introduced by USB3 spec (Set SEL and Set Isoch Delay),
as well as one patch, which has been pending for a long time,
implementing LPM support.

Last, but not least, we are splitting the host address space
out of the dwc3 core driver otherwise xHCI won't be able to
request_mem_region() its own address space. This patch is
only needed because we are (as we should) re-using the xHCI
driver, which is a completely separate module.

Together with these three big changes, come a few extra preparatory
patches which most move code around, define macros and so on, as
well as a fix for Isochronous transfers which hasn't been triggered
before.

[ resolved conflicts and build error in drivers/usb/dwc3/gadget.c - gregkh]
2012-05-07 10:09:55 -07:00
Ido Shayevitz
16e78db720 usb: dwc3: Update dwc3 udc to use usb_endpoint_descriptor inside the struct usb_ep
Remove redundant pointer to struct usb_endpoint_descriptor.

Signed-off-by: Ido Shayevitz <idos@codeaurora.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-05-04 15:52:52 +03:00
Felipe Balbi
c12a0d862a usb: dwc3: ep0: implement support for Set Isoch Delay request
This is basically a noop for DWC3. We don't have
to do anything. Basically we test if the request
parameters are correct, cache the Isochronous
Delay and return success.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-05-02 09:43:09 +03:00
Felipe Balbi
865e09e716 usb: dwc3: ep0: implement Set SEL support
This patch implements Set SEL Standard Request
support for dwc3 driver. It needs to issue a command
to the controller passing the timing we received on
the data phase of the Set SEL request.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-05-02 09:43:08 +03:00
Sebastian Andrzej Siewior
e6a3b5e288 usb: dwc3: ep0: add LPM handling
On device loading the driver enables LPM and the acceptance of U1 and U2
states. The [Set|Clear]Feature requests for "U1/U2" are forwarded
directly to the hardware and allow / forbid the initiation of the low
power links.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-04-30 11:31:21 +03:00
Gerard Cauvy
ecb07797ff usb: dwc3: ep0: add a default case for SetFeature command
Without this default case returning an error,
thus replying with a stall, we would fail
USB30CV TD 9.11 Bad Feature test case.

Cc: stable@vger.kernel.org
Signed-off-by: Gerard Cauvy <g-cauvy1@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-04-10 19:11:31 +03:00
Felipe Balbi
cd423dd363 usb: dwc3: ep0: increment "actual" on bounced ep0 case
due to a HW limitation we have a bounce buffer for ep0
out transfers which are not aligned with MaxPacketSize.

On such case we were not increment r->actual as we should.

This patch fixes that mistake.

Cc: stable@vger.kernel.org
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-04-10 12:21:44 +03:00
Moiz Sonasath
566ccdda07 usb: dwc3: ep0: Handle requests greater than wMaxPacketSize
To allow ep0 out transfers of upto bounce buffer size
instead of maxpacketsize, use the transfer size as multiple
of ep0 maxpacket size.

Cc: stable@vger.kernel.org
Signed-off-by: Moiz Sonasath <m-sonasath@ti.com>
Signed-off-by: Partha Basak <p-basak2@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-04-10 12:21:43 +03:00
Greg Kroah-Hartman
3d71769014 usb: dwc3: changes for v3.4 merge window
Here are the changes for v3.4 merge window.
 
 It includes a new glue layer for Samsung's Exynos platform, a simplification of
 memory management on DWC3 driver by using dev_xxx functions, a few
 optimizations to IRQ handling by dropping memcpy() and using bitshifts, a fix
 for TI's OMAP5430 TX Fifo Allocation, two fixes on USB2 test mode
 implementation (one on debugfs and one on ep0), and several minor changes such
 as whitespace cleanups, simplification of a few parts of the code, decreasing a
 long delay to something a bit saner, dropping a header which was included twice
 and so on.
 
 The highlight on this merge is the support for Samsung's Exynos platform,
 increasing the number of different users for this driver to three.
 
 Note that Samsung Exynos glue layer will only compile on platforms which
 provide implementation for the clk API for now. Once Samsung supports
 pm_runtime, that limitation can be dropped from the Makefile.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.11 (GNU/Linux)
 
 iQIcBAABAgAGBQJPUJ2bAAoJEIaOsuA1yqREwOgP/2bG6rvPBMlGmXvvR40HNUXJ
 jXzkXcrTBrO172Fxl2P+mAgNFggMURrOdiyXwl7+2Ib0NM7sS9jwikuxos8DwuQv
 Ci0GgJtQySORIl5Sw29uB1W65aV2ieNBh/fN/52LwVOQYITt89GYK1DsRUWRN2V/
 0bw3OepckiAFN5gWRykIYIUXZs8DQa+L1qYc6fexZk7zZ+XrjdNba8RzGzsyUelD
 BB0eOj4E2Mda6Yp7kyiBRuTXVAUChNa5J0iCvXSnR8l2wppfXlmD2UD4Sfo/yxd5
 q25/rm1e1A4iKcPjSkhzTayQKrLWEgCxZK69sZXlEPG9qhA3iMjWDNBvEy6cV4bc
 bFFjwXAObX+bm+QDYqcD66iUZTPzEW149W/e5B7+XGk09NcCs/wqoA1jEgCLEHnv
 3rsG0RvsgtMdwmBYpO8zrhJPTFa6NAq9Qc4nLj3WefXP9Vkl5gpfneIcgYKB6x0q
 LHRQsLHBWl/hXClWAPflDJaGQqEt6hjkA3IqV03yTlMNuYxDNJy931J6Cz9a9Lu5
 Gr2By/bHVcADmt8WzituQsnLvQIzLLGl0U0lKpdl24I52roqMkZVj7XaWDojLVSq
 HZnbk+c3PdEXVIDNCz1QnCY/QojEhKkeR23LP3YD8L9KxcOu8DNyL1RKdYqx3Cnv
 vrqerutPusT6kGvaRQIk
 =4Z2+
 -----END PGP SIGNATURE-----

Merge tag 'dwc3-for-v3.4' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next

usb: dwc3: changes for v3.4 merge window

Here are the changes for v3.4 merge window.

It includes a new glue layer for Samsung's Exynos platform, a simplification of
memory management on DWC3 driver by using dev_xxx functions, a few
optimizations to IRQ handling by dropping memcpy() and using bitshifts, a fix
for TI's OMAP5430 TX Fifo Allocation, two fixes on USB2 test mode
implementation (one on debugfs and one on ep0), and several minor changes such
as whitespace cleanups, simplification of a few parts of the code, decreasing a
long delay to something a bit saner, dropping a header which was included twice
and so on.

The highlight on this merge is the support for Samsung's Exynos platform,
increasing the number of different users for this driver to three.

Note that Samsung Exynos glue layer will only compile on platforms which
provide implementation for the clk API for now. Once Samsung supports
pm_runtime, that limitation can be dropped from the Makefile.

Conflicts:
	drivers/usb/dwc3/gadget.c
2012-03-02 15:56:33 -08:00
Paul Zimmerman
c2df85ca31 usb: dwc3: clear 'res_trans_idx' as soon as it becomes invalid
Transfer resource index is cleared in hardware when XFERCOMPLETE
event is generated, so clear the driver's res_trans_idx variable
immediately after that event is received. The upcoming hibernation
patches depend on this change.

Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-03-02 12:12:11 +02:00
Paul Zimmerman
1d04679395 usb: dwc3: clean up whitespace damage, typos, missing parens, etc.
trivial patch, no functional changes

Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-03-02 12:12:01 +02:00
Greg Kroah-Hartman
f9b0f51709 This merge is rather big. Here's what it contains:
For am5536udc we have just simple coding style fixes. Nothing that has any
 potential to cause any issues going forward.
 
 With mv_udc, there's only one single change removing an unneeded NULL check.
 
 at91_udc also only saw a single change this merge window, and that's only
 removing a duplicated header.
 
 The Renesas controller has a few more involved changes. Support for SUDMAC was
 added, there's now a special handling of IRQ resources for when the IRQ line is
 shared between Renesas controller and SUDMAC, we also had a bug fix where
 Renesas controller would sleep in atomic context while doing DMA transfers from
 a tasklet. There were also a set of minor cleanups.
 
 The FSL UDC also had a scheduling in atomic context bug fix, but that's all.
 
 Thanks to Sebastian, the dummy_hcd now works better than ever with support for
 scatterlists and streams. Sebastian also added SuperSpeed descriptors to the
 serial gadgets.
 
 The highlight on this merge is the addition of a generic API for mapping and
 unmapping usb_requests. This will avoid code duplication on all UDC controllers
 and also kills all the defines for DMA_ADDR_INVALID which UDC controllers
 sprinkled around. A few of the UDC controllers were already converted to use
 this new API.
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.11 (GNU/Linux)
 
 iQIcBAABAgAGBQJPTeaWAAoJEIaOsuA1yqREdT8QAK8ob6RqnZs9en7NdaBTq18G
 qPtdheAZ9TkWxv+JE69Nqq1DuLO93+ZqLt88kaIVp/jTg+MxZ4qeANe9Nga0Qr+U
 Qc4d9HOkKsLGC+E45TApAMCQkPZ3DxbObJRUeJI7DBefPJ+MzQYAeeQtzjEeKKf8
 hGY5kh5FdXds/TlTePwWuyVoe09grgoy7cvptIVJRZiWx8+n9PZeMiKe+vAmQDEc
 +V0FfOMZLcSY9Oi14faYDrOFIV5cjBxnwnBpinOYx5TArxep35HSynt/mJtW2a7/
 lcdpbS4Hn35LJQWcYl0onx0GNgvI/YDYg9V6vrSjoBVU7vZ/7slZ896yjiovmAsc
 KQXxKoqss80sd+rYUe/si/Ues+koN9HztucG//+9cuS2ZCnDydHMJHonMBXUZguv
 o2gzQwjRCUOcGLj+vnSAFiBAGZwAZV99rA2VgIz3dSyegDN+SverXJscOuvzzW/V
 6yERLjbmxwtIQczlUMPQgGE9gSMYKRzyDV4JlO1xtfsBwcVc0c4YE+ZnWOeEAbOa
 evrI/3RGjP12rY+eyntlN2ZpHq2ZJnS7guDjooi0mGK16LWeQh8h0zD24XoUiwnr
 nhkv+eqWJQXV2iQcyezO1TLnxhZ7LZdtfkYg5MH/VqGIuh6SNQdhew4bijUuKKsq
 +aLPREySYHdIloQjPBe/
 =RR+f
 -----END PGP SIGNATURE-----

Merge tag 'gadget-for-v3.4' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next

USB: Gadget: changes for 3.4

This merge is rather big. Here's what it contains:

For am5536udc we have just simple coding style fixes. Nothing that has any
potential to cause any issues going forward.

With mv_udc, there's only one single change removing an unneeded NULL check.

at91_udc also only saw a single change this merge window, and that's only
removing a duplicated header.

The Renesas controller has a few more involved changes. Support for SUDMAC was
added, there's now a special handling of IRQ resources for when the IRQ line is
shared between Renesas controller and SUDMAC, we also had a bug fix where
Renesas controller would sleep in atomic context while doing DMA transfers from
a tasklet. There were also a set of minor cleanups.

The FSL UDC also had a scheduling in atomic context bug fix, but that's all.

Thanks to Sebastian, the dummy_hcd now works better than ever with support for
scatterlists and streams. Sebastian also added SuperSpeed descriptors to the
serial gadgets.

The highlight on this merge is the addition of a generic API for mapping and
unmapping usb_requests. This will avoid code duplication on all UDC controllers
and also kills all the defines for DMA_ADDR_INVALID which UDC controllers
sprinkled around. A few of the UDC controllers were already converted to use
this new API.

Conflicts:
	drivers/usb/dwc3/gadget.c
2012-03-01 09:20:28 -08:00
Felipe Balbi
0fc9a1be09 usb: dwc3: gadget: use generic map/unmap routines
those routines have everything we need to map/unmap
USB requests and it's better to use them.

In order to achieve that, we had to add a simple
change on how we allocate and use our setup buffer;
we cannot allocate it from coherent anymore otherwise
the generic map/unmap routines won't be able to easily
know that the GetStatus request already has a DMA
address.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-28 14:48:54 +02:00
Felipe Balbi
f6bafc6a1c usb: dwc3: convert TRBs into bitshifts
this will get rid of a useless memcpy on
IRQ handling, thus improving driver performance.

Tested with OMAP5430 running g_mass_storage on
SuperSpeed and HighSpeed.

Note that we are removing the little endian access
of the TRB and all accesses will be in System endianness,
if there happens to be a system in BE, bit 12 of GSBUSCFG0
should be set so that HW does byte invariant BE accesses
when fetching TRBs.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-13 16:02:06 +02:00
Gerard Cauvy
3b637367ae usb: dwc3: ep0: fix SetFeature(TEST)
When host requests us to enter a test mode,
we cannot directly enter the test mode before
Status Phase is completed, otherwise the core
will never be able to deliver the Status ZLP
to host, because it has already entered the
requested Test Mode.

In order to fix the error, we move the actual
start of Test Mode right after we receive
Transfer Complete event of the status phase.

Signed-off-by: Gerard Cauvy <g-cauvy1@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-10 13:11:46 +02:00
Felipe Balbi
457e84b662 usb: dwc3: gadget: dynamically re-size TxFifos
We need to dynamically re-size TxFifos for the
cases where default values will not do.

While at that, we create a simple function which,
for now, will just allocate one full packet fifo
space for each of the enabled endpoints.

This can be improved later in order to allow for
better throughput by allocating more space for
endpoints which could make good use of that like
isochronous and bulk.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-06 11:48:34 +02:00
Felipe Balbi
bb5cfd6811 usb: dwc3: ep0: move to CONFIGURED also on delayed status
Mass Storage gadget will take some time to handle
the SetConfiguration request, but even on those
cases we should move to CONFIGURED state.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-06 11:48:31 +02:00
Felipe Balbi
04a9bfcd50 usb: dwc3: gadget: re-factor USB2 test mode to a function
There are some situations were we might need to
enable USB Test Modes without having access to a
Host stack. In such situations we cannot rely
solely on USB Control Messages to enable test
features.

For those cases, we will also allow test mode
to be enabled via debugfs and this patch is a
preparation for that.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-02-06 11:48:19 +02:00
Felipe Balbi
1a0955fed1 usb: dwc3: ep0: fix compile warning
commit 34c60a7 (usb: dwc3: ep0: tidy up Pending
Request handling) introduced a compile warning
by leaving an unused variable.

This patch fixes that warning:

drivers/usb/dwc3/ep0.c: In function ‘__dwc3_gadget_ep0_queue’:
drivers/usb/dwc3/ep0.c:129:8: warning: unused variable ‘type’
[-Wunused-variable]

Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-01-24 15:42:25 +02:00
Felipe Balbi
68d8a78157 usb: dwc3: ep0: tidy up Pending Request handling
The way our code was written, we should never have
a DWC3_EP_PENDING_REQUEST flag set out of a Data Phase
and the code in __dwc3_gadget_ep0_queue() did not
reflect that situation properly.

Tidy up that case to avoid any possible mistakes
when starting requests for IRQs which are long
gone.

Cc: stable@vger.kernel.org
Signed-off-by: Felipe Balbi <balbi@ti.com>
2012-01-24 15:41:22 +02:00
Felipe Balbi
68d3e668d2 usb: dwc3: ep0: fix for possible early delayed_status
There is a very small possibility (previously unimagined
by us) that the whole Mass Storage delayed status happens
rather early, before we even get our XferNotReady event.

In that case, we will be queueing a request to ep0 while
we're still on Setup Phase and we would be waiting for
another usb_ep_queue() forever.

Handle such cases by clearing dwc->delayed_status so that
we start control status from the next XferNotReady like
there was no wait for Delayed Status.

Tested against Linux 3.2-rc3 and USB30CV tool from USB-IF
(on a Windows XP with USB3 PCIe card).

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:47 +02:00
Felipe Balbi
e261779605 usb: dwc3: ep0: fix GetStatus handling (again)
previous commit fixed part of it but it was still
calling usb_ep_queue() from IRQ context without
loosing locks. That cannot be done otherwise we will
have a recursive locking.

Also, we need to assign the 'dep' pointer on
dwc->ep0_usb_req otherwise we will have a NULL
pointer dereference on dwc3_map_buffer_to_dma().

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:46 +02:00
Sebastian Andrzej Siewior
e0ce0b0a0a usb: dwc3: ep0: use dwc3_request for ep0 requsts instead of usb_request
Instead of special functions and shortcuts for sending our internal
answers to the host we started doing what the gadget does and used the
public API for this. Since we only were using a few fields the
usb_request was enough. Later added the list handling in order to
synchronize the host / gadget events and now we require to have the
dwc3_request struct around our usb_request or else we touch memory that
does not belong to us. So this patch does this.

Reported-by: Partha Basak <p-basak2@ti.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:45 +02:00
Felipe Balbi
df62df56e1 usb: dwc3: workaround: missing disconnect event
DWC3 revisions <1.88a have an issue which would
case a missing Disconnect event if cable is
disconnected while there's a Setup packet
pending the FIFO.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:42 +02:00
Sebastian Andrzej Siewior
5bdb1dcc63 usb: dwc3: ep0: handle delayed_status again
Since the re-worked ep0 handling (which uses HW's hints to recognize the ep0
status) we lost the delayed status handling. This is used by the file and mass
storage gadget to gain some extra time so setup its internal status before it
can proceed further requests.
In particular the storage gadget does nothing on USB_REQ_SET_CONFIGURATION but
wakes up a thread which handles the request. If the udc driver continues ep0
handling before the thread did its work then then endpoint is not yet
configured and further requests will fail. Once the gadget is ready, it will
enqueue an empty packet which is used for synchronization.
In order to fix this issue, the patch does the following:
Set ->delayed_status once the delayed_status has been notices and do not
continue on the next XferNotReady event. We will continues ep0 processing once
the gadget enqueued the zero packet for synchronization.

A cleaner approach would be to enforce the gadget to enqueue an empty
(zero) request even for the status phase but this would do for now.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:31 +02:00
Sebastian Andrzej Siewior
f0f2b2a2db usb: dwc3: ep0: push ep0state into xfernotready processing
We wait for the XferNotReady before we start the transfer and by then we
know ep0 state in which we supposed to be.
This is some cleanup work for the following patch in which we require to
know the ep0 state before the transfer completes.
While here, also change the argument to dwc3_ep0_do_control_status() so
we don't require the complete event structure but only the required
piece of information.

Inspired-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:30 +02:00
Felipe Balbi
8becf27044 usb: dwc3: fix sparse errors
sparse caught three mistakes on this driver,
fix them:

drivers/usb/dwc3/ep0.c:806:29: warning: duplicate const
drivers/usb/dwc3/debugfs.c:481:15: warning: symbol 'dwc3_debugfs_init' \
	was not declared. Should it be static?
drivers/usb/dwc3/debugfs.c:518:16: warning: symbol 'dwc3_debugfs_exit' \
	was not declared. Should it be static?

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:29 +02:00
Felipe Balbi
25b8ff68bf usb: dwc3: fix few coding style problems
There were a few coding style issues with this driver
which are now fixed:

drivers/usb/dwc3/debugfs.c:48: WARNING: Use #include \
	<linux/uaccess.h> instead of <asm/uaccess.h>
drivers/usb/dwc3/debugfs.c:484: ERROR: space required \
	before the open brace '{'
drivers/usb/dwc3/ep0.c:261: WARNING: line over 80 characters
drivers/usb/dwc3/ep0.c:287: WARNING: suspect code indent \
	for conditional statements (16, 23)
drivers/usb/dwc3/gadget.c:749: WARNING: line over 80 characters
drivers/usb/dwc3/gadget.c:1267: WARNING: line over 80 characters
drivers/usb/dwc3/gadget.h:116: WARNING: line over 80 characters
drivers/usb/dwc3/io.h:42: WARNING: Use #include \
	<linux/io.h> instead of <asm/io.h>

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:29 +02:00
Sebastian Andrzej Siewior
c2da2ff006 usb: dwc3: ep0: don't use ep0in for transfers
In "usb: dwc3: remove special status request handling in ep0" I simplied
a few things and used the generic API for the status transfers. The bug
I introcuded here is that we queue now requests to dep[1] but we don't
clear that list in the stall+start case.
Actually we don't need to use dep[1] at all. We only did in the past to
talk to the correct endpoint (i.e. in or out). This is now take care of
in a diffent place within the ep0 code. So we could queue the in
transfers to dep[0] and don't use dep[1] at all.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:25 +02:00
Sebastian Andrzej Siewior
1e7618d8a1 usb: dwc3: ep0: use proper endianess in SetFeature for wIndex
The first access was correct, the second was wrong.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:25 +02:00
Sebastian Andrzej Siewior
8ee6270c7f usb: dwc3: remove special status request handling in ep0
The GetStatus (STD)-request is handled the driver and uses a tiny hack
to send the two bytes long answer. This patch removes the custom hack
uses the normal usb_ep_queue() for that.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:21 +02:00
Sebastian Andrzej Siewior
0cc7a519c4 usb: dwc3: reset pending status flag in error case
If we stall and restart we have to reset also this flag to 0 as there is
nothing pending anymore.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:20 +02:00
Felipe Balbi
9cc9bcd5b3 usb: dwc3: ep0: handle unexpected XferNotReady events
Sometimes the host might be trying to initiate Data or
Status phase for an older Control transfer. In such
situations we must STALL that transfer and restart
the state machine rather than letting such situation
go through the wire.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:16 +02:00
Felipe Balbi
f96a6ec1db usb: dwc3: ep0: SetAddress() won't be issued while Configured
I have talked to USB-IF about USB30CV issuing SetAddres()
with a device on Configured state and they have agreed on
changing USB30CV not to do so.

Adding back the STALL reply in such case and while at
that, also add a debugging message for an address which
is too large.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-12-12 11:48:15 +02:00
Felipe Balbi
dc1c70a774 usb: dwc3: convert structures into bitshifts
our parameter structures need to be written to
HW, so instead of assuming little endian, we
convert those into bit shifts.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:56 -07:00
Paul Zimmerman
b23c843992 usb: dwc3: gadget: fix DEPSTARTCFG for non-EP0 EPs
DEPSTARTCFG for non-EP0 EPs must only be sent once per config

[ balbi@ti.com : changed config_start to start_config_issued ]

Signed-off-by: Paul Zimmerman <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:52 -07:00
Sebastian Andrzej Siewior
49a25cc9a7 usb: dwc: remove "All rights reserved" statement.
Some people think that this line is not compatible with the GPL. The
statement was required due to the Buenos Aires Convention and is now
deprecated. I remove it because it is said that it is pointless nowdays.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:52 -07:00
Sebastian Andrzej Siewior
b147f3572d usb: dwc3: ep0: fix debug output
Use "ep0in" and "ep0out" instead "ep1in" and "ep0out" which is confusing
and not consistent with the remaining output.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:51 -07:00
Sebastian Andrzej Siewior
9876cbe2e2 usb: dwc3: ep0: remove second giveback in error case
We already give requests back in dwc3_ep0_stall_and_restart() so
doing it again here will most likely corrupt the list.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:51 -07:00
Felipe Balbi
25355be64e usb: dwc3: ep0: fix debug message
The way it was before was really meaningless.
Now it looks saner.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:51 -07:00
Felipe Balbi
d95b09b901 usb: dwc3: ep0: ignore direction on 2-stage transfer
We don't need to care about direction on a two stage
transfer.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:50 -07:00
Felipe Balbi
2646021e1d usb: dwc3: ep0: Make USB30CV happy with SetAddress
According to USB 3.0 Specification, a SetAddress()
while device is in Configured State has an unspecified
behavior (see Section 9.4.6). Still USB30CV wasn't
happy with my Stall reply.

To make that thing happy, just accept the SetAddress()
always. No problems have been observed thus far.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-10-04 10:25:50 -07:00
Felipe Balbi
55f3fba6c8 usb: dwc3: ep0: introduce ep0_expect_in flag
This flag will tell us which direction we're
expecting on the next (data or status) phase.

It will help us catching errors of host going
crazy and requesting data of the wrong direction.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:05:29 +03:00
Felipe Balbi
d742220b35 usb: dwc3: ep0: giveback requests on stall_and_restart
if we don't, the list will be busy forever.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:05:28 +03:00
Felipe Balbi
1ddcb218b5 usb: dwc3: use ep0_next_event field
Start tracking the next expected event and act
on the error conditions as suggested by databook.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:18 +03:00
Felipe Balbi
0b7836a9eb usb: dwc3: drop EP0_STALL state
Whenever we issue a Set Stall command on EP0,
the state machine will be restarted and Stall
is cleared automatically, when core receives
the next SETUP packet.

There's no need to track that EP0_STALL state.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:17 +03:00
Felipe Balbi
76cb323f80 usb: dwc3: ep0: clear all EP0 flags
when we're going to issue Set Stall command,
we should clear DWC3_EP_STALL flag, but also
we should clear BUSY, HALTED and all others.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:16 +03:00
Felipe Balbi
b673cf3002 usb: dwc3: ep0: fix Get Status handling
data was prepared on setup_buf but transfer
was started on ctrl_req, fix it.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:15 +03:00
Felipe Balbi
c7fcdeb262 usb: dwc3: ep0: simplify EP0 state machine
The DesignWare USB3 core tells us which phase
of a control transfer should be started, it
also tells us which physical endpoint needs
that transfer.

With these two informations, we have all we
need to simply EP0 handling quite a lot and
get rid rid of the SW state machine tracking
ep0 states.

For achieving this perfectly, we needed to
add support for situations where we get
XferNotReady while endpoint is still busy
and XferNotReady while gadget driver still
hasn't queued a request.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:07 +03:00
Felipe Balbi
a6829706ce usb: dwc3: ep0: add handling for unaligned OUT transfers
In case we have transfers which aren't aligned
to wMaxPacketSize, we need to be careful with
how we start the transfer with the HW. OUT
transfers _must_ be aligned with wMaxPacketSize
and in order to guarantee that, we use a bounce
buffer.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:05 +03:00
Felipe Balbi
c611ccb48a usb: dwc3: ep0: fix 'transfered' typo
trivial patch. No functional changes.

Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-09-09 13:02:00 +03:00
Felipe Balbi
72246da40f usb: Introduce DesignWare USB3 DRD Driver
The DesignWare USB3 is a highly
configurable IP Core which can be
instantiated as Dual-Role Device (DRD),
Peripheral Only and Host Only (XHCI)
configurations.

Several other parameters can be configured
like amount of FIFO space, amount of TX and
RX endpoints, amount of Host Interrupters,
etc.

The current driver has been validated with
a virtual model of version 1.73a of that core
and with an FPGA burned with version 1.83a
of the DRD core. We have support for PCIe
bus, which is used on FPGA prototyping, and
for the OMAP5, more adaptation (or glue)
layers can be easily added and the driver
is half prepared to handle any possible
configuration the HW engineer has chosen
considering we have the information on
one of the GHWPARAMS registers to do
runtime checking of certain features.

More runtime checks can, and should, be added
in order to make this driver even more flexible
with regards to number of endpoints, FIFO sizes,
transfer types, etc.

While this supports only the device side, for
now, we will add support for Host side (xHCI -
see the updated series Sebastian has sent [1])
and OTG after we have it all stabilized.

[1] http://marc.info/?l=linux-usb&m=131341992020339&w=2

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-08-22 16:03:11 -07:00