Commit graph

563782 commits

Author SHA1 Message Date
Jack Pham
1e50e387dd usb: dwc3-msm: Remove POST_INIT notification
This notification for this event is no longer used, so remove it.

Signed-off-by: Jack Pham <jackp@codeaurora.org>
2016-03-22 11:07:04 -07:00
Jack Pham
80cc0c0836 usb: dwc3: Add support to suspend SS phy
Upstream commit 636e2a2cae
(usb: dwc3: gadget: drop dwc3 manual phy control) removed the
support to suspend the PHYs since the recent controller versions
can do that automatically.
But MSM targets, still do not have the latest controller and hence
adding back the functionality to suspend/resume SS phy.

Change-Id: I02a7ae8daf194a645f3582480f5a6b7d504b32ec
Signed-off-by: Jack Pham <jackp@codeaurora.org>
2016-03-22 11:07:03 -07:00
Hemant Kumar
a4a1da4956 usb: dwc3: Add support for GSI operations to gadget framework
Targets supporting h/w accelerated path over GSI require
GSI specific configuration of USB controller.

Add support to enable h/w accelerated path to IPA.
Include operations to configure USB endpoints as
GSI capable, allocate TRBs that are associated with
GSI capable endpoints, perform operations on these
endpoints, and enable the GSI wrapper in DWC3 controller.
This allows a function driver to use GSI based h/w
accelerated data path.

Change-Id: I62688c70a04b1fdab3e522e0af759ebab69d92d7
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
2016-03-22 11:07:02 -07:00
Azhar Shaikh
13e9b08d2d Revert "usb: dwc3: Reset the transfer resource index on SET_INTERFACE"
commit a0c760181ca874 ("usb: dwc3: Reset the transfer resource index
on SET_INTERFACE") was resetting the start_config_issued flag on
receiving SetInterface request. But in cases where transfer resource
index is shared between two endpoints and if both are trying to do a
transfer then transfer on one of the endpoints will fail, since the
transfer resource index will be acquired by the first endpoint
and when the second endpoint tries to get the same transfer resource
index, it will fail and hence STARTTRANSFER command also fails on second
endpoint.
Reverting this change ensures endpoints get allocated with unique
transfer resource index.

CRs-fixed: 953585
Change-Id: I7800356e455900cc39b9463366275c68db777199
Signed-off-by: Azhar Shaikh <azhars@codeaurora.org>
2016-03-22 11:07:01 -07:00
Azhar Shaikh
9230a73e6b usb: dwc3: Offload IRQ handling to softirq context
Move interrupt handling from threaded IRQ context to a tasklet.
This may help in reducing latencies associated with starvation
caused by high priority softirq over threaded USB IRQ.

Change-Id: I2f988be9c484a6ee59236d9dfd7f06f07414ee96
Signed-off-by: Azhar Shaikh <azhars@codeaurora.org>
2016-03-22 11:07:00 -07:00
Mayank Rana
6fc5b622c8 usb: dwc3: Don't check usb isochronous endpoint check for ep0
Commit 5ad02fb813 ("usb: dwc3: gadget: move isoc endpoint check
to unlocked set_halt") moved usb isochronous endpoint check form
dwc3_gadget_ep_set_halt() to __dwc3_gadget_ep_set_halt().
dwc3_gadget_ep_set_halt() API is being called explicitly by USB
function driver to stalls USB endpoints whereas
__dwc3_gadget_ep_set_halt() API is also being called to stall ep0
on receiving invalid setup packet or not able to queue response
to setup packet. It is not supposed to have any descriptors with
ep0 early stage of enumeration process. Hence revert change which
makes sure to check usb endpoint type against isochronous before
halting endpoint with dwc3_gadget_ep_set_halt() instead of
__dwc3_gadget_ep_set_halt().

Change-Id: I24b3e78613bf89340c812e353dafaf384ac4a057
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
2016-03-22 11:06:59 -07:00
Mayank Rana
cda82d5273 usb: dwc3: Clear pending events when it is bigger than event buffer size
Currently there exists a race condition between dwc3_gadget_run_stop()
and dwc3 gadget interrupt handling. run_stop() could get cleared and set
again in between hard IRQ and threaded IRQ contexts, the DWC3_GEVNTCOUNT
could first get set to 0, and then written again in the threaded handler
with a non-zero value. Writing back to this register will cause hardware
to decrement the value, and since it is 0 will result in a high unsigned
value (~65k).

To handle this condition mark received events as processed and return
IRQ_HANDLED if events count is bigger than event buffer size. Note that
the root cause of this condition will be addressed in another patch that
prevents the race by synchronizing the hard and threaded interrupt handlers
with dwc3_gadget_run_stop() getting called asynchronously.

Change-Id: I4d6ade8243867885f26876a5233a8456a7e8bf42
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
2016-03-22 11:06:58 -07:00
Jack Pham
869c733233 usb: dwc3: Disable ep0 and interrupts when clearing run/stop
In dwc3_gadget_run_stop() when clearing the run/stop bit, ensure
that IRQs are masked and the ep0 in and out endpoints are disabled.
In case pullups are removed while a control transfer is in progress,
this makes sure that the control endpoints are properly cleaned up.
If and when run/stop is set again, the function already re-enables
the IRQ and ep0 when calling dwc3_gadget_restart(). While at it,
memset() the event buffers to clear stale contents when
reinitializing them in dwc3_event_buffers_setup().

Also, since calling dwc3_gadget_disable_irq() only masks the
interrupts at the controller layer, it might not catch instances
where an IRQ itself may have already been asserted but does not
arrive at the handler until after the pullups are removed. Add a
check to dwc3_interrupt() to catch this case as well.

Change-Id: Ie58979fe4b229240231760652189338ec5343a2d
Signed-off-by: Jack Pham <jackp@codeaurora.org>
2016-03-22 11:06:57 -07:00
Mayank Rana
a43ebbb862 usb: dwc3: Replace WARN_ON() by WARN_ON_ONCE() and logging with buffer
In some of cases when ep0 operations are fails, WARN_ON is called from
interrupt context. This may lead to watchdog bark if repeated WARN_ON
condition occurs. Hence replace usage of WARN_ON() by WARN_ON_ONCE() and
logging errror as part of debug buffer.

CRs-Fixed: 907077
Change-Id: I40de055b1e8d610c43c7fff32cd904c43b9bec00
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
2016-03-22 11:06:57 -07:00
Hemant Kumar
1abf160f23 usb: dwc3: Allocate TRB pool upon enabling endpoint
Currently gadget driver is by default allocating dma TRB
pool per endpoint for 30 endpoints upon driver probe.
Optimize this by allocating dma memory only for enabled
endpoints.

Change-Id: I378a42d0b84fa43f7c20cd025cd9361c467cb41b
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
2016-03-22 11:06:56 -07:00
Mayank Rana
6fd132c4c0 dwc3: gadget: Use default TX FIFO size as 1024 bytes with each IN eps
Commit d8a39efaa477 ("dwc3: gadget: Improve TX FIFO resize functionality")
is considering USB enumerated speed to allocate TX FIFO size for each IN
endpoints. This change simplifies this by using 1024 bytes as default
TXFIFO size with each IN endpoints.

Change-Id: I55b5886c824d9b689ac8496f50f6e0e784afae98
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
2016-03-22 11:06:55 -07:00
Mayank Rana
47576f9878 dwc3: gadget: Avoid processing of trb if HWO bit is set
HWO bit signifies that TRB is still pending with hardware. Hence
avoid processing of TRB if HWO bit is set.

Change-Id: I6d4068eb9e6934f68e7b6204cac8f6f3266dabf4
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
2016-03-22 11:06:54 -07:00
Mayank Rana
feb12aaa55 dwc3: Increase event buffer size to 8KB from 256 bytes
Commit 5da9347825 ("usb: dwc3: decrease event buffer size") has
decreased controller's event buffer size to 256 bytes which results
into multiple overflow events. Receiving of overflow events suggests
that software is not able to process received events fast enough
which results into losing of those events. Fix this issue by
increasing event buffer size to 8KB.

Change-Id: I37f6203f0b6d87098d57b2ce0ba8a3a0b8ef5bd2
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
2016-03-22 11:06:53 -07:00
Mayank Rana
ef0629fbde dwc3: gadget: Improve TX FIFO resize functionality
This change considers USB device speed to set max_packet size
instead of provided max_packet value from USB function driver.
It doesn't resize ep0IN TxFIFO, and starts with ep1IN TxFIFO only.

Change-Id: Ifce63f5a8570f79bad1e5d3ae6f5d580c34046b5
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
2016-03-22 11:06:52 -07:00
Mayank Rana
32db5976ed dwc3: gadget: Initialized USB TRBs pool memory with zero
dma_coherent_alloc() API doesn't guaranteed that allocated memory
is initialized with zero. It is observed in some cases where there
is stale data seen with allocated memory for TRB pool and providing
this TRB with USB controller results into different memory access
issues. Fix this issue by using dma_zalloc_coherent() API which
allocates memory and initialized it with zero.

Change-Id: I160e319aace262958a11ba5196f53ec21b98977f
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
2016-03-22 11:06:51 -07:00
Ido Shayevitz
865addc7d4 drivers: usb: dwc3: Add XMIT_DEV command
Starting with synopsis version 220A the command to wake up the
host changed from 0x3 to 0x7. The code is fixed accordingly.
The problem that was seen is that upon MBIM function
suspend, a remote wakeup from the IPA side wouldn't
wake up the host, and at some point a stall in the IPA would be
seen.

CRs-fixed: 695414
Change-Id: I6ef5c649f263f388a1cc92a3db71c14c741b5b71
Signed-off-by: Lena Salman <esalman@codeaurora.org>
Signed-off-by: Ido Shayevitz <idos@codeaurora.org>
2016-03-22 11:06:50 -07:00
Hemant Kumar
d8a457b42d usb: dwc3-msm: Bring controller out of LPM early upon system resume
In case of host initiated usb bus resume upon system suspend controller
exits from LPM as part of dwc3 PM resume. Since call to dwc3 PM resume
from PM framework involves latency due to which usb device misses the
timeline of response for bus resume. This results into host issuing warm
reset. Hence bring controller out of LPM in power event irq thread context.
Set IRQF_EARLY_RESUME for power event irq which reduces irq level latency
by enabling this irq early during system resume. Also, save power event
irq time stamp to track latency between hard irq and irq thread.

CRs-Fixed: 804476
Change-Id: Ib5470c6046ffbfff55b89e717f040bd6435454da
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
2016-03-22 11:06:49 -07:00
Mayank Rana
2991c5cf8c dwc3: gadget: Ignore suspend event if USB is not into CONFIGURED state
For reboot usecase with some of host machine, it has been observed that
Suspend event is being received in between USB enumeration process which
is highly unlikely case. Although due to this event, device side USB goes
into suspend state which cause USB device enumerates as unknown device
with host machine. Fix this issue by ignoring suspend event until USB
enumeration process is not being completed i.e. device side USB is not
reach into CONFIGURED state.

Add check for CONFIGURED state with controller suspend routine as well
to make sure that if this routine finds controller into L2 state before
it performs LPM functionality, it confirms that state of USB as
CONFIGURED.

CRs-Fixed: 717151
Change-Id: I86925f22edf94c526a3b7504333501b6e27412d7
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
2016-03-22 11:06:48 -07:00
Mayank Rana
b371a833e6 usb: dwc3: core: Disable internal clock gating conditionally
Currently USB DWC3 controller's internal clock gating is disabled
unconditionally. In few platform, it is possible to enable internal
clock gating with controller. Hence this change adds support to
disable this functionality conditionally using "snps,disable-clk-gating"
device tree property. With this change USB controller's internal clock
gating is enabled by default.

CRs-Fixed: 851877
Change-Id: I17d43a23d3bff0cb516b952c35c4a13af53f7777
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
2016-03-22 11:06:47 -07:00
Mayank Rana
7d2a036a4e dwc3: gadget: Add NULL check against endpoint's desc in set_halt()
In few instances, dwc3_gadget_ep_set_halt() API is called after USB
endpoint is disabled which results into device crash with NULL pointer
dereference. USB endpoint's descriptors are set to NULL as part of USB
endpoint disable functionality. Hence fix this issue by adding NULL
pointer check against endpoint's descriptor.

CRs-Fixed: 829034
Change-Id: I2e1f67571ed202fab21655bd8f13fc54706419a7
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
2016-03-22 11:06:47 -07:00
Jack Pham
710341d1cf usb: dwc3: Ignore multiple U3/L2 suspend events
The controller may sometimes generate back-to-back suspend
interrupt events. Ignore the repeated events to avoid calling
the gadget driver's suspend callback multiple times.

Change-Id: I284b461adeab5911388efd8bb7ecbf39a85c86ca
Signed-off-by: Jack Pham <jackp@codeaurora.org>
2016-03-22 11:06:46 -07:00
Jack Pham
78c60a7bf6 usb: dwc3: gadget: Keep track of IRQ timing statistics
It may be useful to debug how much time is spent in the
DWC3 hard IRQ context. Add low-overhead statistics counters
which keep a histogram of the last 10 interrupts' time of
occurence, time spent, and number of events read (which will
get processed in the bottom half handler).

Change-Id: I466144d8141f4236b9fb834dded93225b56d0422
Signed-off-by: Jack Pham <jackp@codeaurora.org>
2016-03-22 11:06:45 -07:00
Manu Gautam
13a30395d6 DWC3: gadget: Report error if RX buffer not aligned to EP's MTU
Synopsys USB3 Controller (DWC3) has a restriction where size
of OUT requests (TRB) queued to the controller must be aligned
with the endpoint's max packet size. Hence, report error in case
function driver tries to queue an unaligned request.

Change-Id: Id5f4a0ff9d2f9c55bba936d683608c524eadd260
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
2016-03-22 11:06:44 -07:00
Mayank Rana
fcc26a6a54 usb: dwc3: Fall back to high speed when SSPHY fails
In some cases, it has been observed that SSPHY fails to initialized.
This change detects this condition and configures controller to work
into high speed mode only.

Change-Id: I50c4041d8572d0cdc4535812eebd10fc18b78e98
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
2016-03-22 11:06:43 -07:00
Jack Pham
0071b357da usb: dwc3: gadget: Fix calculation of request.actual for SG
When a request completes, cleanup_done_trbs() tries to calculate
request.actual by subtracting the TRB remainder from the original
request.length, but does not account for scatter-gather requests
that queued multiple TRBs. In this case, the request.length field
may be used by the function to keep track of the aggregate length
of all the provided SG entries, and thus will produce an incorrect
request.actual. Instead, for scatter-gather, to find the pre-transfer
buffer length of each TRB, get the length field of each SG entry.
Then the number of bytes transfered can be correctly determined as
the difference between that and the bytes remaining in the TRB.

Change-Id: I4c197462ce5b804c9d684240e95c35b532976220
Signed-off-by: Jack Pham <jackp@codeaurora.org>
2016-03-22 11:06:42 -07:00
Hemant Kumar
4e32ea8f3b usb: dwc3: Do not call WARN_ON_ONCE from interrupt context
Gadget driver calls WARN_ON_ONCE in some of the APIs which
are called from interrupt context. This may lead to watchdog
bark if repeated WARN_ON_ONCE condition occurs. Hence print
error message and/or log it in debug buffer.

CRs-Fixed: 747698
Change-Id: Ieecd6342135e7d2bad36c82a12958b78054150db
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
2016-03-22 11:06:41 -07:00
Jack Pham
b0b1bb5940 usb: dwc3: gadget: Resolve recursive spinlock during remote wakeup
When a USB function wishes to send new data during USB suspend state, it
needs to issue USB remote wakeup and send a function wakeup notification
after then. This scenario leads to recursive spin locking inside the
_usb_func_wakeup() function, because this function gets called recursively.
This function issues remote wakeup, which internally calls the resume
interrupt callback, which calls the _usb_func_wakeup() function again.
This issue is resolved by performing the remote wakeup in a deferred work
context, and this splits the recursion loop.

CRs-fixed: 700667
Change-Id: I59c8efde098781587d29f08cd60e4aa3521949d8
Signed-off-by: Danny Segal <dsegal@codeaurora.org>
2016-03-22 11:06:41 -07:00
Hemant Kumar
c6d80a92b7 usb: dwc3: gadget: Prevent tx fifo resize before set config
If device took longer than expected time queuing zlp in status
stage host issues bus reset. As a result tx fifio resize happens
at status stage of first control transfer after bus reset. This
causes null pointer dereference for config pointer as device is
not in configured state yet. Hence clear the resize_fifos flag
upon bus reset to avoid this situation. Also add NULL check in
dwc3_gadget_resize_tx_fifos().

CRs-Fixed: 747688
Change-Id: Icd50eaa15f75c1b0bd7e2f8db5550ad54af47ef8
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
2016-03-22 11:06:40 -07:00
Mayank Rana
3bbd6278f2 dwc3: gadget: Clear per endpoint ring buffer when disabling endpoint
Current code is not clearing ring buffer once it is being initialized.
Issue is seen where xferinprogress interrupt is received with
isochronous endpoint due to stale TRB (for isochronous endpoint we
are using LINK TRB), we enqueue new request buffer using update
transfer command. If stale TRB is having HWO bit being set, controller
is trying to execute that particular TRB which results into error on
bus as that request buffer is already being freed or used by other
subsystem. Fix this issue by clearing per endpoint ring buffer when
disabling endpoint.

CRs-Fixed: 782340
Change-Id: I46e6a46400367d6ebf55bdb445a3330c0a4d77e1
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
2016-03-22 11:06:39 -07:00
Vijayavardhan Vennapusa
4083e89ea0 USB: dwc3: Fix issues in isochronous endpoint handling
If there are no requests queued by function driver when
XFRNRDY interrupt is recieved, pending flag will be set.
Then if function driver queues request, don't queue ENDTXFR
command and wait for XFRNRDY interrupt.

START TRANSFER command will fail if the interval for which
requests are being queued is already expired. Handle this
case by queueing ENDXFER command and waiting till recieves
XFRNRDY interrupt.

Change-Id: I9498be3967e0f80b05cf0830affe5463f07e2976
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
Signed-off-by: Jack Pham <jackp@codeaurora.org>
2016-03-22 11:06:38 -07:00
Mayank Rana
def08da7f5 usb: dwc3: Add error print messages
There is a possible race that arises when gadget events are processed
before the resume routine has disabled the USB2 PHY autosuspend. Some
of the gadget events issue endpoint commands which may time out since
the PHY is still autosuspended. Add error messages to help debug
these failurs.

Signed-off-by: Mayank Rana <mrana@codeaurora.org>
2016-03-22 11:06:37 -07:00
Jack Pham
f0487e67e5 usb: dwc3: Adjust TX FIFO allocation
Optimize the dwc3_gadget_resize_tx_fifos() function to better
allocate the per-endpoint FIFOs depending on a number of factors:

	- super- or non-super speed
	- bulk/isoc with bursting
	- reduced RAM (when QDSS uses some internal RAM)
	- endpoint enabled in composition

Signed-off-by: Jack Pham <jackp@codeaurora.org>
2016-03-22 11:06:36 -07:00
Danny Segal
88ffd6eb95 usb: dwc: Fix function wakeup during suspend on SW path
When the SW wants to start USB traffic during USB bus suspend state, it
needs to issue remote-wakeup signaling to the USB host before sending the
function wakeup notification. This patch changes the function wakeup
sending notification function to check whenter the USB bus is suspended
and issue remote-wakeup if needed.

CRs-Fixed: 678203
Change-Id: I1b09e7763c821a0a0e62095b4dc1c8621a2316b3
Signed-off-by: Danny Segal <dsegal@codeaurora.org>
2016-03-22 11:06:35 -07:00
Danny Segal
635cdb12e4 gadget: dwc: Support remote wakeup bit in GET_STATUS command in HS-USB mode
In High-Speed mode, the remote wakeup feature is enabled by a SET_FEATURE
command sent from the host. This patch adds the logic reflect this
configuration in the device GET_STATUS command response.

Change-Id: I0c934d0330d2580f15b1307005dde7b4b7874a7d
Signed-off-by: Danny Segal <dsegal@codeaurora.org>
2016-03-22 11:06:34 -07:00
Danny Segal
8f171cb53f usb: dwc: add support for super-speed function suspend
The USB 3.0 specification defines a new 'Function Suspend' feature.
This feature enables the USB host to put inactive composite device
functions in a suspended state even when the device itself is not
suspended.
This patch extends the existing framework of USB dwc driver
to properly support the 'Function Resume' and 'Function Remote Wakeup'
related features.

Change-Id: If7bbfa7d6a4ff70d4b44ede5fc258370b890df47
Signed-off-by: Danny Segal <dsegal@codeaurora.org>
2016-03-22 11:06:34 -07:00
Jack Pham
9e134dbb1b usb: gadget: Add udc_priv member to struct usb_request
This member is used to store additional private flags
for BAM-enabled functions to pass information to the UDC.

Signed-off-by: Jack Pham <jackp@codeaurora.org>
2016-03-22 11:06:33 -07:00
Bar Weiner
fb759c4758 usb: dwc3: gadget: allow running wakeup in delayed context
Adding the option of running the gadget wakeup function
from the context in which it is called, or delaying it - in case
it is called from an atomic context. This is required in order
to support a case where the gadget is in lpm and the wakeup
would result in a queue to the low-powered hardware.

Change-Id: I09fc60e75c79202c97251146aab1539de3307424
Signed-off-by: Bar Weiner <bweiner@codeaurora.org>
Signed-off-by: Danny Segal <dsegal@codeaurora.org>
Signed-off-by: Jack Pham <jackp@codeaurora.org>
2016-03-22 11:06:32 -07:00
Vijayavardhan Vennapusa
567c83ebc7 USB: dwc3: Add support for fixing superspeed enumeration issue
Setting SSPHY SUSP bit (bit 17) in GUSB3PIPECTL(0) register
might cause device enumerating at high speed mode instead of
superspeed mode on some platforms. Hence add workaround by
clearing the SSPHY SUSP bit during disconnect and setting it
after it is configured to fix this enumeration issue on those
platforms.

Also add support for disabling U1 and U2 low power modes  which
could also affect this enumeration issue.

CRs-Fixed: 637902
Change-Id: I8668ced09a88b77f37265ab15e89fa9e964bfbe9
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
[jackp@codeaurora.org: only add u1/u2 disable bits]
Signed-off-by: Jack Pham <jackp@codeaurora.org>
2016-03-22 11:06:31 -07:00
Bar Weiner
01edad63c9 usb: dwc3: add in_lpm flag to struct dwc3
This change provides the gadget with awareness regarding
the vendor-specific's low-power-mode status. This is done
in order to enable proper decision making regarding cases
where the gadget would potentially attempt to interface the
hardware when it's in lpm.

Change-Id: I1508fbddd13228fbb7d6d53d91d98a0acaaf3fd7
Signed-off-by: Bar Weiner <bweiner@codeaurora.org>
2016-03-22 11:06:30 -07:00
Bar Weiner
87ac720b8a usb: dwc3: add support for pwr_event_irq
Adds support for the pwr_event_irq in general, and for
the L1_OUT pwr event specifically. The support consists of:
1. Enabling the pwr_event_irq based on the DT.
2. Adding a threaded irq handler as well as a centralized function
   (dwc3_pwr_event_handler()) for handling the various power events.
3. Enabling the L1_OUT pwr event. This is done on an
   arch-by-arch basis. The trigger for enabling this is
   dbm_l1_lpm_interrupt().
4. Calling usb_gadget_wakeup() in order to initiate a wakeup sequence
   without sending a remote-wakeup indication to the host.
5. Adding a call from dwc3_msm_resume() to dwc3_pwr_event_handler().
   This is done in order to overcome a situation where
   dwc3_msm_suspend() would have disabled the clocks, thereby
   disabling the ability to read the PWR_STAT register before calling
   the handler function.

Change-Id: Ia548ec2e9ee4a7c6634c87ba24fe4cdbf1221000
Signed-off-by: Dov Levenglick <dovl@codeaurora.org>
Signed-off-by: Bar Weiner <bweiner@codeaurora.org>
2016-03-22 11:06:29 -07:00
Dov Levenglick
94e3cbb5f2 usb: dwc3: gadget: ignore suspend interrupt before connect
The controller sees a suspend event prior to the the cable connect
or reset events. As a result, it runs through an unnecessary
suspend sequence. Adding a check on the gadget's state avoids
the overhead.
The root cause of this appears to be a situation where the
controller senses/is told that there is a VBUS, but the port
reset is not forthcoming. In such a case, the line state is
interpreted as suspend, and the event is generated.
When VBUS detach is sensed/indicated, the state is returned to
USB_STATE_NOTATTACHED, in preparation for the next cable connect.

Change-Id: I639454ceb0ad3a8ff2c02d527c553a934b8639fc
Signed-off-by: Dov Levenglick <dovl@codeaurora.org>
2016-03-22 11:06:28 -07:00
Jack Pham
abeac45ef6 usb: dwc3: Add missing defines
Add bit definition for the GUSB2PHYCFG ENBLSLPM bit.
Add definition for DWC3_GUCTL_REFCLKPER which is used to set
the reference clock frequency. Also add definition for
DWC3_GDBGLTSSM_LINKSTATE_MASK used to query the HW for
the current LTSSM link state.

Signed-off-by: Jack Pham <jackp@codeaurora.org>
2016-03-22 11:06:27 -07:00
Bar Weiner
a1ee10d4cc usb: dwc3: gadget: allow remote-wakeup for SS-USB
Remove the restriction in the code that disables the possibility
of device remote wakeup in SS-USB.
Originally, this restriction was coded since suspend/resume in SS-USB
is expected to be performed at the function level, rather than the
device level. However, the suspend is currently done at the device
level, and therefore the corresponding remote wakeup should also
follow in suit.
The concept of function suspend/resume may be revisited in the future.

Change-Id: If071f38c03cf46290536cafad1a13a6818088eb7
Signed-off-by: Bar Weiner <bweiner@codeaurora.org>
2016-03-22 11:06:27 -07:00
Mayank Rana
7fcaf72280 usb: dwc3: Keep track of interrupt statistics
This change adds debug support to log all received different
events with endpoint0, other endpoints and gadget events. It
tracks these events per endpoint and displays the same.

For each of the endpoint event counters, add the rate (in Hz)
at which it occurs in order to better analyze performance and
aid in optimization.

How to use:
- Mount debugfs
- To see received all dwc3 events/interrupts
cat /sys/kernel/debug/<base_address>.dwc3/int_events
- To clear all received dwc3 events/interrupts
echo 0 > /sys/kernel/debug/<base_address>.dwc3/int_events

Change-Id: Ibf5f3ee57f69c87f94f55a58f50792075be24fbb
Signed-off-by: Gilad Broner <gbroner@codeaurora.org>
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
2016-03-22 11:06:26 -07:00
Dov Levenglick
ce73ca32ca usb: dwc3: gadget: start resume sequence on remote-wakeup
As per Synopsys databook, the USB controller does not
trigger a wakeup event when remote-wakeup is used.
Hence, after remote-wakeup sequence is complete, and
the device is back at U0 state, it is required that
the resume sequence is initiated manually by SW.

Change-Id: I2f147d4a0644088b948b1798627c7717c35c0104
Signed-off-by: Bar Weiner <bweiner@codeaurora.org>
Signed-off-by: Dov Levenglick <dovl@codeaurora.org>
2016-03-22 11:06:25 -07:00
Jack Pham
c694893be5 usb: dwc3: gadget: Protect against ep disabling during completion
In dwc3_cleanup_done_reqs(), a potential race condition
could arise when dwc3_gadget_giveback() temporarily
releases the main spinlock.  If during this window the
very endpoint being handled becomes disabled, it would
lead to a NULL pointer dereference in the code that
follows.  Guard against this by making sure the endpoint
is still enabled after returning from the giveback call.

CRs-fixed: 628972
Change-Id: Ifdb823fff12747f699217d871a5959c85b5340f7
Signed-off-by: Jack Pham <jackp@codeaurora.org>
2016-03-22 11:06:24 -07:00
Mayank Rana
06b8c38125 dwc3: Disable USB Link state(U1/U2) change events
Currently all USB Link state change events are enable which are
triggering huge number of interrupts to the cpu. Disable U1/U2 Link
state entry/exit events by using dwc_usb3_devten register. Below is
one of test results showing the same.
Test case: Run tethered RMNET UDP UL/DL Modem looback with 50M bandwidth
Test duration: 120 seconds
Test Results :
- with USB Link state change events enable:
CPU Idle : 42%, Number of USB Link state change events: 3769013
- with USB Link state change events disable:
CPU Idle : 51%, Number of USB Link state change events: 0
These numbers (cpu usage, number of interrupts) are taken for
120 seconds duration of test execution.

This change also does enable U3L2L1SuspEn event (BIT:6)  to get U3
notification and handling suspend part. Wakeup event is already enabled
which takes care of USB resuming.

CRs-Fixed: 610718
Change-Id: Ied6da6699849a3136a35de0b9a27ee18086daeab
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
2016-03-22 11:06:23 -07:00
Jack Pham
78c2759dea usb: dwc3: Stop processing more events after erratic error
In rare cases if the controller is unable to communicate with the
PHY it will trigger an ERRATIC ERROR event, upon which it is
recommended that the controller be reset. Currently the reset
is scheduled to be performed in a workqueue, which relinquishes
the dwc3_interrupt thread to continue to process the event buffer.
Meanwhile if the reset runs concurrently, it would disable the core
clock, which would result in unclocked I/O access if the gadget
interrupt handling continues to run. Fix this by stopping the
interrupt thread and prevent further interrupts from reading DWC3
registers until the reset sequence has completed.

Change-Id: Ib9a2173867d2ce3c9dbc5f5cbff0dda554168b35
Signed-off-by: Jack Pham <jackp@codeaurora.org>
2016-03-22 11:06:22 -07:00
Jack Pham
d675e70190 usb: dwc3: gadget: Handle erratic error event only once
DWC3 databook suggests that upon receiving erratic error event
software should reset the controller. The way in which the
driver currently handles interrupts by offloading event processing
to a threaded handler could result in a long sequence of received
erratic errors in the event queue. dwc3_gadget_interrupt() could
then end up processing a large number of the same event unnecessarily.

In the case of dwc3-msm, this results in KERN_INFO messages flooding
the console. Fix this by only handling erratic error once. Add
a state variable to keep track of when it is seen, and clear it
once a non-error event is processed.

Change-Id: I5deeb2a614f9002867472a0e4aa26a61f0413ceb
Signed-off-by: Jack Pham <jackp@codeaurora.org>
2016-03-22 11:06:21 -07:00
Jack Pham
0b937c189f usb: dwc3: gadget: Ensure core is not suspended when handling interrupt
Since dwc3_thread_interrupt is part of interrupt handling that
can be scheduled to run in thread context, it leaves open a
window in which the controller might be placed into low power
mode. In this state, clocks would be disabled, and by the time
dwc3_thread_interrupt runs, would result in an unclocked I/O
access when it tries to write to the GEVNTCOUNT register.

Prevent this by calling pm_runtime_get() in dwc3_interrupt() in
order to force the device to remain in active state, which
increments the parent device's child count so that it too is
prevented from entering suspend. Call pm_runtime_put() at the
end of dwc3_thread_interrupt() after finishing processing the
event buffers.

CRs-fixed: 609233
CRs-fixed: 622850
Change-Id: Ia21c9ac74d74833a889081f41c93acec2a7ae011
Signed-off-by: Jack Pham <jackp@codeaurora.org>
2016-03-22 11:06:21 -07:00