Commit graph

752379 commits

Author SHA1 Message Date
Felipe Balbi 6afbdb5773 usb: dwc3: gadget: one declaration per line
Misc cleanup. No functional changes.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:56 +03:00
Felipe Balbi e0c42ce590 usb: dwc3: gadget: simplify IOC handling
We will only have event status of IOC when IOC bit is set in
TRB. There's no need to check both bits.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:56 +03:00
Felipe Balbi d80fe1b6e3 usb: dwc3: gadget: simplify short packet event
We know that only OUT endpoints can trigger SHORT. We also know that
count MUST be > 0 whenever SHORT triggers.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:56 +03:00
Felipe Balbi b27972b508 usb: dwc3: trace: print out event status too
This will make it easier to figure out the reason for the event. That
information really helps debugging certain problems.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:56 +03:00
Felipe Balbi 8b3b7b66c0 usb: dwc3: gadget: simplify unaligned and zlp handling
We can just call reclaim_trb_linear instead of reimplementing it.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:55 +03:00
Felipe Balbi cf35fc336e usb: dwc3: gadget: remove unnecessary 'chain' variable
Minor cleanup, no functional changes.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:55 +03:00
Felipe Balbi 021595963a usb: dwc3: gadget: remove PENDING handling from cleanup_completed
We are trying to kick transfers on Isochronous endpoints in a more
controlled manner now. And this ended up rendering this piece of code
unnecessary.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:55 +03:00
Felipe Balbi d36929538f usb: dwc3: gadget: split scatterlist and linear handlers
instead of having one big loop, let's split it down into two smaller
handlers: one for linear buffers and one for scatterlist.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:54 +03:00
Felipe Balbi d5044a04b5 usb: dwc3: gadget: simplify isoc case on cleanup_completed_requests
Just a minor simplification, no functional changes.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:54 +03:00
Felipe Balbi fe990cea8e usb: dwc3: gadget: simplify queueing of isoc transfers
After all the previous changes, it's now a lot clearer how isoc
transfers should be managed. We don't need to try to End Transfers
from ep_queue since that's already done by cleanup_requests.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:54 +03:00
Felipe Balbi 4d588a145b usb: dwc3: gadget: remove duplicated missed isoc handling
Now, this part of the code is duplicated and brings no extra value to
the driver. Let's remove it.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:53 +03:00
Felipe Balbi 6d8a019614 usb: dwc3: gadget: check for Missed Isoc from event status
In case we get an event with status set to Missed Isoc, this means we
have missed an isochronous interval and should issue End Transfer
command and wait for the following XferNotReady.

Let's do that early, rather than late.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:53 +03:00
Felipe Balbi 58f0218a27 usb: dwc3: gadget: remove unnecessary 'ioc' variable
It's only written to, never read. We can remove it now.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:53 +03:00
Felipe Balbi 12a3a4ada8 usb: dwc3: gadget: make cleanup_completed_requests() return nothing
We don't need to return a value anymore here. Let's remove it.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:52 +03:00
Felipe Balbi 5f2e7975f0 usb: dwc3: gadget: remove DWC3_EP_BUSY flag
It has no use anymore.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:52 +03:00
Felipe Balbi 1912cbc60f usb: dwc3: gadget: start removing BUSY flag
By now, it has the same semantics as DWC3_EP_TRANSFER_STARTED, but
that has a much more descriptive name.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:52 +03:00
Felipe Balbi ee3638b897 usb: dwc3: gadget: update dep->frame_number from XferInprogress too
We will need an up-to-date frame_number from XferInProgress too when
future patches improve our handling of Isoc endpoints.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:51 +03:00
Felipe Balbi 5828cada99 usb: dwc3: gadget: always use frame number from XferNotReady
The core requires the extra two bits of information for properly
scheduling Isochronous transfers. This means that we can't rely on
__dwc3_gadget_get_frame(). Let's always cache uFrame number from
XferNotReady instead.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:51 +03:00
Felipe Balbi 8f608e8ab6 usb: dwc3: gadget: remove unnecessary 'dwc' parameter
Endpoint handlers need to know about endpoints, not dwc. If they
really need access to dwc (e.g. for printing error messages) we have a
reference to it tucked inside the endpoint.

This patch has no functional changes, it's simply moving things around.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:51 +03:00
Felipe Balbi 320338651d usb: dwc3: gadget: move handler closer to calling site
Cleanup only, no functional changes. Just making code easier to
follow.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:50 +03:00
Felipe Balbi ed27442e50 usb: dwc3: gadget: rename dwc3_gadget_start_isoc()
Cleanup only, no functional changes. This just matches the event name
with its handler.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:50 +03:00
Felipe Balbi a24a6ab149 usb: dwc3: gadget: remove some pointless checks
We *KNOW* which events we enable for which endpoint types and
we *KNOW* when they'll trigger. The endpoint type checks are
pointless.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:50 +03:00
Felipe Balbi 0bd0f6d201 usb: dwc3: gadget: remove allocated/queued request tracking
That has never proven useful in any way. Just remove it.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:50 +03:00
Felipe Balbi 66f5dd5a03 usb: dwc3: gadget: rename done_trbs and done_reqs
This patch simply renames two functions to more descriptive names so
that it's easier to understand what they're doing.

Cleanup only, no functional changes.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:49 +03:00
Felipe Balbi a861282f50 usb: dwc3: gadget: don't kick transfer all the time
Instead of constantly calling kick transfer everything some event
shows up, let's just rely on the fact that we send Update Transfer
every time a new request is queued.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:49 +03:00
Felipe Balbi fbea935acc usb: dwc3: gadget: rename dwc3_endpoint_transfer_complete()
Now that we're making sure we don't have XferComplete events, we can
rename this function to what it actually handles:
dwc3_gadget_endpoint_transfer_in_progress()

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:49 +03:00
Felipe Balbi 742a4fff5f usb: dwc3: gadget: XferComplete only for EP0
XferComplete is enabled only for the default control pipe, let's make
that clear in the code.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:48 +03:00
Felipe Balbi 38408464aa usb: dwc3: gadget: XferNotReady is Isoc-only
We don't use XferNotReady for anything other than Default Control
Pipe, which is handled in ep0.c, and Isochronous endpoints. Let's make
that clear in the code.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:48 +03:00
Felipe Balbi 52fcc0bead usb: dwc3: gadget: pre-issue Start Transfer for Interrupt EPs too
Interrupt endpoints behave much like Bulk endpoints with the exception
that they are periodic. We can pre-issue Start Transfer exactly as we
do for Bulk endpoints.

While at that, remove one trailing blank line which is unnecessary.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:48 +03:00
Anurag Kumar Vulisha c96e6725db usb: dwc3: gadget: Correct the logic for queuing sgs
The present code correctly fetches the req which were previously not
queued from the started_list but fails to continue queuing from the sg
where it previously stopped queuing (because of the unavailable TRB's).
This patch correct's the code to continue queuing from the correct sg
present in the sglist.

For example, consider 5 sgs in req. Because of limited TRB's among the
5 sgs only 3 got queued. This patch corrects the code to start queuing
from correct sg i.e 4th sg when the TRBs are available.

Signed-off-by: Anurag Kumar Vulisha <anuragku@xilinx.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:47 +03:00
Anurag Kumar Vulisha a31e63b608 usb: dwc3: gadget: Correct handling of scattergather lists
The code logic in dwc3_prepare_one_trb() incorrectly uses the address
and length fields present in req packet for mapping TRB's instead of
using the address and length fields of scattergather lists. This patch
correct's the code to use sg->address and sg->length when scattergather
lists are present.

Signed-off-by: Anurag Kumar Vulisha <anuragku@xilinx.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-21 10:00:47 +03:00
Andrzej Hajda 5f0b74e548 USB: dwc3: get extcon device by OF graph bindings
extcon device is used to detect host/device connection. Since extcon
OF property is deprecated, alternative method should be added.
This method uses OF graph bindings to locate extcon.

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-16 08:56:16 +03:00
Masahiro Yamada fe8abf332b usb: dwc3: support clocks and resets for DWC3 core
Historically, the clocks and resets are handled on the glue layer
side instead of the DWC3 core.  For simple cases, dwc3-of-simple.c
takes care of arbitrary number of clocks and resets.  The DT node
structure typically looks like as follows:

  dwc3-glue {
          compatible = "foo,dwc3";
          clocks = ...;
          resets = ...;
          ...

          dwc3 {
                  compatible = "snps,dwc3";
                  ...
          };
  }

By supporting the clocks and the reset in the dwc3/core.c, it will
be turned into a single node:

  dwc3 {
          compatible = "foo,dwc3", "snps,dwc3";
          clocks = ...;
          resets = ...;
          ...
  }

This commit adds the binding of clocks and resets specific to this IP.
The number of clocks should generally be the same across SoCs, it is
just some SoCs either tie clocks together or do not provide software
control of some of the clocks.

I took the clock names from the Synopsys datasheet: "ref" (ref_clk),
"bus_early" (bus_clk_early), and "suspend" (suspend_clk).

I found only one reset line in the datasheet, hence the reset-names
property is omitted.

Those clocks are required for new platforms.  Enforcing the new
binding breaks existing platforms since they specify clocks (and
resets) in their glue layer node, but nothing in the core node.
I listed such exceptional cases in the DT binding.  The driver
code has been relaxed to accept no clock.  This change is based
on the discussion [1].

I inserted reset_control_deassert() and clk_bulk_enable() before the
first register access, i.e. dwc3_cache_hwparams().

[1] https://patchwork.kernel.org/patch/10284265/

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-16 08:52:39 +03:00
Romain Izard 4d4ca0139c usb: gadget: udc: atmel: Fix indenting
Fix the fallout of the conversion to GPIO descriptors in 3df0340810.

Acked-by: Ludovic Desroches <ludovic.desroches@microchip.com>
Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
Signed-off-by: Romain Izard <romain.izard.pro@gmail.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-15 10:24:48 +03:00
Romain Izard 2f8519f6ed usb: gadget: udc: atmel: Remove obsolete include
The include defines the private platform_data structure used with AVR
platforms. It has no user since 7c55984e19. Remove it.

Acked-by: Ludovic Desroches <ludovic.desroches@microchip.com>
Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
Signed-off-by: Romain Izard <romain.izard.pro@gmail.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-15 10:24:47 +03:00
Romain Izard a3e20083bd usb: gadget: udc: atmel: GPIO inversion is handled by gpiod
When converting to GPIO descriptors, gpiod_get_value automatically
handles the line inversion flags from the device tree.

Do not invert the line twice.

Fixes: 3df0340810 ("usb: gadget: udc: atmel: convert to use GPIO descriptors")
Acked-by: Ludovic Desroches <ludovic.desroches@microchip.com>
Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
Signed-off-by: Romain Izard <romain.izard.pro@gmail.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-15 10:24:44 +03:00
Michel Pollet 1ca532e991 USB: rndis: Fix for handling garbled messages
A message can be forged to crash the stack; here we make sure we don't
completely break the system if this occurs

Signed-off-by: Michel Pollet <michel.pollet@bp.renesas.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-15 10:24:28 +03:00
Masahiro Yamada 44feb8e6ea usb: dwc3: use local copy of resource to fix-up register offset
It is not a good idea to directly modify the resource of a platform
device.  Modify its local copy, and pass it to devm_ioremap_resource()
so that we do not need to restore it in the failure path and the remove
hook.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-15 10:23:47 +03:00
Chunfeng Yun 1ef6c42afc usb: gadget: composite: fill bcdUSB as 0x0320 for SuperSpeed or higher speeds
The USB3CV version 2.1.80 (March 26, 2018) requires all devices
( gen1, gen2, single lane, dual lane) to return the value of 0x0320
in the bcdUSB field

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-15 10:22:21 +03:00
Manu Gautam bcb128777a usb: dwc3: core: Suspend PHYs on runtime suspend in host mode
Some PHY drivers (e.g. for Qualcomm QUSB2 and QMP PHYs) support
runtime PM to reduce PHY power consumption during bus_suspend.
Add changes to let core auto-suspend PHYs on host bus-suspend
using GUSB2PHYCFG register if needed for a platform. Also perform
PHYs runtime suspend/resume and let platform glue drivers e.g.
dwc3-qcom handle remote wakeup during bus suspend by waking up
devices on receiving wakeup event from PHY.

Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-15 10:20:32 +03:00
Manu Gautam a4333c3a6b usb: dwc3: Add Qualcomm DWC3 glue driver
DWC3 controller on Qualcomm SOCs has a Qscratch wrapper.
Some of its uses are described below resulting in need to
have a separate glue driver instead of using dwc3-of-simple:
 - It exposes register interface to override vbus-override
   and lane0-pwr-present signals going to hardware. These
   must be updated in peripheral mode for DWC3 if vbus lines
   are not connected to hardware block. Otherwise RX termination
   in SS mode or DP pull-up is not applied by device controller.
 - pwr_events_irq_stat support to check if USB2 PHY is in L2 state
   before glue driver proceeds with suspend.
 - Support for wakeup interrupts lines that are asserted whenever
   there is any wakeup event on USB3 or USB2 bus.
 - Support to replace pip3 clock going to DWC3 with utmi clock
   for hardware configuration where SSPHY is not used with DWC3.

Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-15 10:20:13 +03:00
Manu Gautam c18aba9005 dt-bindings: usb: Update documentation for Qualcomm DWC3 driver
Existing documentation has lot of incorrect information as it
was originally added for a driver that no longer exists.

Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-15 10:20:12 +03:00
Icenowy Zheng e362098f0e usb: dwc3: of-simple: Add compatible for Allwinner H6 platform
Add compatible string to use this generic glue layer to support
Allwinner H6 platform's dwc3 controller.

Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-15 10:18:35 +03:00
Lukasz Nowak d3ac41bb33 usb: gadget: f_ecm: fix host mac address for multiple instances
In case there are multiple ecm instances, either for multiple
otg controllers, or multiple virtual links using libcomposite,
each instance needs to have its own host mac address string
value for iMACAddress.

Update the source array (ecm_string_defs), every time before
usb_gstrings_attach(). Without that, all links wrongly were
getting the same, last allocated, host mac address, rather
than the correct one, as requested via configfs.

Signed-off-by: Lukasz Nowak <lukasz.nowak@exablue.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-15 10:17:18 +03:00
John Greb eea52743eb USB: Gadget Ethernet: Re-enable Jumbo frames.
Fixes: <b3e3893e1253> ("net: use core MTU range checking")
which patched only one of two functions used to setup the
USB Gadget Ethernet driver, causing a serious performance
regression in the ability to increase mtu size above 1500.

Signed-off-by: John Greb <h3x4m3r0n@gmail.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-15 10:17:14 +03:00
Artur Petrosyan c7c24e7a04 usb: dwc2: Change reading of current frame number flow.
The current frame_number is read from core for both
device and host modes. Reading of the current frame
number needs to be performed ASAP due to IRQ latency's.
This is why, it is moved to common interrupt handler.

Accordingly updated dwc2_gadget_target_frame_elapsed()
function which uses stored frame_number instead of
reading frame number.

In cases when target frame value is incremented
the frame_number is required to read again.

Signed-off-by: Artur Petrosyan <arturp@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-15 10:17:09 +03:00
Stefan Wahren 971b750d31 usb: dwc2: debugfs: Don't touch RX FIFO during register dump
Dumping the registers via debugfs makes USB on Raspberry Pi completely
unusable. The read of register GRXSTSP ("Receive Status Read and Pop
Register") is responsible for this behaviour, because it pops the RX FIFO.
So avoid this by omitting the relevant register.

CC: Mian Yousaf Kaukab <yousaf.kaukab@intel.com>
Fixes: 563cf017c4 ("usb: dwc2: debugfs: add support for complete register dump")
Acked-by: Minas Harutyunyan <hminas@synopsys.com>
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-15 10:17:00 +03:00
Artur Petrosyan d5d5f07913 usb: dwc2: Fix crash in incomplete isoc intr handlers.
Crash caused by going out of "eps_out" array range.
Iteration on "eps_out" changed to less than "num_of_eps".

Signed-off-by: Artur Petrosyan <arturp@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-15 10:16:50 +03:00
Grigor Tovmasyan b43ebc96e9 usb: dwc2: Add Interpacket Gap(IPG) feature support
Added GHWCFG4_IPG_ISOC_SUPPORTED and DCFG_IPG_ISOC_SUPPORDED
bits definitions to enable/disable IPG feature.

Added ipg_isoc_en core parameter which will indicate IPG support
enable/disable and initialize it.

Signed-off-by: Grigor Tovmasyan <tovmasya@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-15 10:16:47 +03:00
Minas Harutyunyan 37981e0050 usb: dwc2: Enable BNA interrupt for IN endpoints
In DDMA mode required to enable BNA interrupt for
both directions.

Signed-off-by: Minas Harutyunyan <hminas@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2018-05-15 10:16:43 +03:00