History log of /linux-master/drivers/usb/dwc3/ep0.c
Revision Date Author Comments
# f2e0eee4 15-Apr-2024 Thinh Nguyen <Thinh.Nguyen@synopsys.com>

usb: dwc3: ep0: Don't reset resource alloc flag

The DWC3_EP_RESOURCE_ALLOCATED flag ensures that the resource of an
endpoint is only assigned once. Unless the endpoint is reset, don't
clear this flag. Otherwise we may set endpoint resource again, which
prevents the driver from initiate transfer after handling a STALL or
endpoint halt to the control endpoint.

Cc: stable@vger.kernel.org
Fixes: b311048c174d ("usb: dwc3: gadget: Rewrite endpoint allocation flow")
Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/00122b7cc5be06abef461776e7cc9f5ebc8bc1cb.1713229786.git.Thinh.Nguyen@synopsys.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# b311048c 31-Jan-2024 Thinh Nguyen <Thinh.Nguyen@synopsys.com>

usb: dwc3: gadget: Rewrite endpoint allocation flow

The driver dwc3 deviates from the programming guide in regard to
endpoint configuration. It does this command sequence:

DEPSTARTCFG -> DEPXFERCFG -> DEPCFG

Instead of the suggested flow:

DEPSTARTCFG -> DEPCFG -> DEPXFERCFG

The reasons for this deviation were as follow, quoted:

1) The databook says to do %DWC3_DEPCMD_DEPSTARTCFG for every
%USB_REQ_SET_CONFIGURATION and %USB_REQ_SET_INTERFACE
(8.1.5). This is incorrect in the scenario of multiple
interfaces.

2) The databook does not mention doing more
%DWC3_DEPCMD_DEPXFERCFG for new endpoint on alt setting
(8.1.6).

Regarding 1), DEPSTARTCFG resets the endpoints' resource and can be a
problem if used with SET_INTERFACE request of a multiple interface
configuration. But we can still satisfy the programming guide
requirement by assigning the endpoint resource as part of
usb_ep_enable(). We will only reset endpoint resources on controller
initialization and SET_CONFIGURATION request.

Regarding 2), the later versions of the programming guide were updated
to clarify this flow (see "Alternate Initialization on SetInterface
Request" of the programming guide). As long as the platform has enough
physical endpoints, we can assign resource to a new endpoint.

The order of the command sequence will not be a problem to most
platforms for the current implementation of the dwc3 driver. However,
this order is required in different scenarios (such as initialization
during controller's hibernation restore). Let's keep the flow consistent
and follow the programming guide.

Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/c143583a5afb087deb8c3aa5eb227ee23515f272.1706754219.git.Thinh.Nguyen@synopsys.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# e9d40b21 22-Dec-2023 Uttkarsh Aggarwal <quic_uaggarwa@quicinc.com>

usb: dwc: ep0: Update request status in dwc3_ep0_stall_restart

Current implementation blocks the running operations when Plug-out and
Plug-In is performed continuously, process gets stuck in
dwc3_thread_interrupt().

Code Flow:

CPU1

->Gadget_start
->dwc3_interrupt
->dwc3_thread_interrupt
->dwc3_process_event_buf
->dwc3_process_event_entry
->dwc3_endpoint_interrupt
->dwc3_ep0_interrupt
->dwc3_ep0_inspect_setup
->dwc3_ep0_stall_and_restart

By this time if pending_list is not empty, it will get the next request
on the given list and calls dwc3_gadget_giveback which will unmap request
and call its complete() callback to notify upper layers that it has
completed. Currently dwc3_gadget_giveback status is set to -ECONNRESET,
whereas it should be -ESHUTDOWN based on condition if not dwc->connected
is true.

Cc: <stable@vger.kernel.org>
Fixes: d742220b3577 ("usb: dwc3: ep0: giveback requests on stall_and_restart")
Signed-off-by: Uttkarsh Aggarwal <quic_uaggarwa@quicinc.com>
Link: https://lore.kernel.org/r/20231222094704.20276-1-quic_uaggarwa@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 2f28c3c9 03-May-2023 Roy Luo <royluo@google.com>

usb: dwc3: Add error logs for unknown endpoint events

In cases where the controller somehow fails to write to event buffer
memory (e.g. due to incorrect MMU config), the driver would receive
all-zero dwc3 events. However, the abnormal event is silently dropped
as a regular ep0out event.
Add error logs when an unknown endpoint event is received to highlight
the anomaly.

Signed-off-by: Roy Luo <royluo@google.com>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/20230504000129.728316-1-royluo@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 92c08a84 24-Mar-2023 Elson Roy Serrao <quic_eserrao@quicinc.com>

usb: dwc3: Add function suspend and function wakeup support

USB host sends function suspend and function resume notifications to
the interface through SET_FEATURE/CLEAR_FEATURE setup packets.
Add support to handle these packets by delegating the requests to
composite layer. Also add support to handle function wake notification
requests to exit from function suspend state.

Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Signed-off-by: Elson Roy Serrao <quic_eserrao@quicinc.com>
Link: https://lore.kernel.org/r/1679694482-16430-5-git-send-email-quic_eserrao@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 04716168 24-Mar-2023 Elson Roy Serrao <quic_eserrao@quicinc.com>

usb: dwc3: Add remote wakeup handling

An usb device can initate a remote wakeup and bring the link out of
suspend as dictated by the DEVICE_REMOTE_WAKEUP feature selector.
Add support to handle this packet and set the remote wakeup capability.

Some hosts may take longer time to initiate the resume signaling after
device triggers a remote wakeup. So add async support to the wakeup API
by enabling link status change events.

Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Signed-off-by: Elson Roy Serrao <quic_eserrao@quicinc.com>
Link: https://lore.kernel.org/r/1679694482-16430-3-git-send-email-quic_eserrao@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 2b2da657 01-Sep-2022 Wesley Cheng <quic_wcheng@quicinc.com>

usb: dwc3: Avoid unmapping USB requests if endxfer is not complete

If DWC3_EP_DELAYED_STOP is set during stop active transfers, then do not
continue attempting to unmap request buffers during dwc3_remove_requests().
This can lead to SMMU faults, as the controller has not stopped the
processing of the TRB. Defer this sequence to the EP0 out start, which
ensures that there are no pending SETUP transactions before issuing the
endxfer.

Reviewed-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
Link: https://lore.kernel.org/r/20220901193625.8727-2-quic_wcheng@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 359d5a85 17-Aug-2022 Wesley Cheng <quic_wcheng@quicinc.com>

usb: dwc3: Do not service EP0 and conndone events if soft disconnected

There are some operations that need to be ignored if there is a soft
disconnect in progress. This is to avoid having a pending EP0 transfer in
progress while attempting to stop active transfers and halting the
controller.

There were several instances seen where a soft disconnect was able to occur
during early link negotiation, i.e. bus reset/conndone, which leads to the
conndone handler re-configuring EPs while attempting to halt the
controller, as DEP flags are cleared as part of the soft disconnect path.

ep0out: cmd 'Start New Configuration'
ep0out: cmd 'Set Endpoint Transfer Resource'
ep0in: cmd 'Set Endpoint Transfer Resource'
ep1out: cmd 'Set Endpoint Transfer Resource'
...
event (00030601): Suspend [U3]
event (00000101): Reset [U0]
ep0out: req ffffff87e5c9e100 length 0/0 zsI ==> 0
event (00000201): Connection Done [U0]
ep0out: cmd 'Start New Configuration'
ep0out: cmd 'Set Endpoint Transfer Resource'

In addition, if a soft disconnect occurs, EP0 events are still allowed to
process, however, it will stall/restart during the SETUP phase. The
host is still able to query for the DATA phase, leading to a
xfernotready(DATA) event. Since none of the SETUP transfer parameters are
populated, the xfernotready is treated as a "wrong direction" error,
leading to a duplicate stall/restart routine.

Add the proper softconnect/connected checks in sequences that are
potentially involved during soft disconnect processing.

Reviewed-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
Link: https://lore.kernel.org/r/20220817182359.13550-2-quic_wcheng@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 5e76ee96 11-Jul-2022 Wesley Cheng <quic_wcheng@quicinc.com>

usb: dwc3: ep0: Properly handle setup_packet_pending scenario in data stage

During a 3 stage SETUP transfer, if the host sends another SETUP token
before completing the status phase, it signifies that the host has aborted
the current control transfer. Currently, if a setup_packet_pending is
received, there are no subsequent calls to dwc3_ep0_out_start() to fetch
the new SETUP packet. This leads to a stall on EP0, as host does not
expect another STATUS phase as it has aborted the current transfer.

Fix this issue by explicitly stalling and restarting EP0, as well as
resetting the trb_enqueue indexes. (without this, there is a chance the
SETUP TRB is set up on trb_endqueue == 1)

Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
Link: https://lore.kernel.org/r/20220712014403.2977-1-quic_wcheng@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# d1b39dd5 20-May-2022 Kushagra Verma <kushagra765@outlook.com>

usb: dwc3: Fix a repeated word checkpatch warning

Fixes a repeated word checkpatch warning in ep0.c by removing the repeated
'only' word.

Signed-off-by: Kushagra Verma <kushagra765@outlook.com>
Link: https://lore.kernel.org/r/HK0PR01MB2801996E815208393170010FF8D39@HK0PR01MB2801.apcprd01.prod.exchangelabs.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 9d778f0c 04-May-2022 Mayank Rana <quic_mrana@quicinc.com>

usb: dwc3: Fix ep0 handling when getting reset while doing control transfer

According to the databook ep0 should be in setup phase during reset.
If host issues reset between control transfers, ep0 will be in an
invalid state. Fix this by issuing stall and restart on ep0 if it
is not in setup phase.

Also SW needs to complete pending control transfer and setup core for
next setup stage as per data book. Hence check ep0 state during reset
interrupt handling and make sure active transfers on ep0 out/in
endpoint are stopped by queuing ENDXFER command for that endpoint and
restart ep0 out again to receive next setup packet.

Signed-off-by: Mayank Rana <quic_mrana@quicinc.com>
Link: https://lore.kernel.org/r/1651693001-29891-1-git-send-email-quic_mrana@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# c9668379 21-Apr-2022 Thinh Nguyen <Thinh.Nguyen@synopsys.com>

usb: dwc3: ep0: Don't prepare beyond Setup stage

Since we can't guarantee that the host won't send new Setup packet
before going through the device-initiated disconnect, don't prepare
beyond the Setup stage and keep the device in EP0_SETUP_PHASE. This
ensures that the device-initated disconnect sequence can go through
gracefully. Note that the controller won't service the End Transfer
command if it can't DMA out the Setup packet.

Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/6bacec56ecabb2c6e49a09cedfcac281fdc97de0.1650593829.git.Thinh.Nguyen@synopsys.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 2840d6df 14-Apr-2022 Wesley Cheng <quic_wcheng@quicinc.com>

usb: dwc3: EP clear halt leading to clearing of delayed_status

The usb_ep_clear_halt() API can be called from the function driver, and
translates to dwc3_gadget_ep_set_halt(). This routine is shared with when
the host issues a clear feature ENDPOINT_HALT, and is differentiated by the
protocol argument. If the following sequence occurs, there can be a
situation where the delayed_status flag is improperly cleared for the wrong
SETUP transaction:

1. Vendor specific control transfer returns USB_GADGET_DELAYED_STATUS.
2. DWC3 gadget sets dwc->delayed_status to '1'.
3. Another function driver issues a usb_ep_clear_halt() call.
4. DWC3 gadget issues dwc3_stop_active_transfer() and sets
DWC3_EP_PENDING_CLEAR_STALL.
5. EP command complete interrupt triggers for the end transfer, and
dwc3_ep0_send_delayed_status() is allowed to run, as delayed_status
is '1' due to step#1.
6. STATUS phase is sent, and delayed_status is cleared.
7. Vendor specific control transfer is finished being handled, and issues
usb_composite_setup_continue(). This results in queuing of a data
phase.

Cache the protocol flag so that DWC3 gadget is aware of when the clear halt
is due to a SETUP request from the host versus when it is sourced from a
function driver. This allows for the EP command complete interrupt to know
if it needs to issue a delayed status phase.

Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
Link: https://lore.kernel.org/r/20220414073902.21960-1-quic_wcheng@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# e4cf6580 09-Mar-2022 Thinh Nguyen <Thinh.Nguyen@synopsys.com>

usb: dwc3: gadget: Wait for ep0 xfers to complete during dequeue

If a Setup packet is received but yet to DMA out, the controller will
not process the End Transfer command of any endpoint. Polling of its
DEPCMD.CmdAct may block setting up TRB for Setup packet, causing a
command timeout.

This may occur if the driver doesn’t service the completion interrupt of
the control status stage yet due to system latency, then it won’t
prepare TRB and start the transfer for the next Setup Stage. To the host
side, the control transfer had completed, and the host can send a new
Setup packet at this point.

In the meanwhile, if the driver receives an async call to dequeue a
request (triggering End Transfer) to any endpoint, then the driver will
service that End transfer first, blocking the control status stage
completion handler. Since no TRB is available for the Setup stage, the
Setup packet can’t be DMA’ed out and the End Transfer gets hung.

The driver must not block setting up of the Setup stage. So track and
only issue the End Transfer command only when there’s Setup TRB prepared
so that the controller can DMA out the Setup packet. Delay the End
transfer command if there's no Setup TRB available. This is applicable to
all DWC_usb3x IPs.

Co-developed-by: Wesley Cheng <quic_wcheng@quicinc.com>
Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
Link: https://lore.kernel.org/r/20220309205402.4467-1-quic_wcheng@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 9f607a30 10-Jul-2021 Wesley Cheng <wcheng@codeaurora.org>

usb: dwc3: Resize TX FIFOs to meet EP bursting requirements

Some devices have USB compositions which may require multiple endpoints
that support EP bursting. HW defined TX FIFO sizes may not always be
sufficient for these compositions. By utilizing flexible TX FIFO
allocation, this allows for endpoints to request the required FIFO depth to
achieve higher bandwidth. With some higher bMaxBurst configurations, using
a larger TX FIFO size results in better TX throughput.

By introducing the check_config() callback, the resizing logic can fetch
the maximum number of endpoints used in the USB composition (can contain
multiple configurations), which helps ensure that the resizing logic can
fulfill the configuration(s), or return an error to the gadget layer
otherwise during bind time.

Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>
Link: https://lore.kernel.org/r/1625908395-5498-4-git-send-email-wcheng@codeaurora.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 40edb522 28-Jun-2021 Linyu Yuan <linyyuan@codeaurora.org>

usb: dwc3: avoid NULL access of usb_gadget_driver

we found crash in dwc3_disconnect_gadget(),
it is because dwc->gadget_driver become NULL before async access.
7dc0c55e9f30 ('USB: UDC core: Add udc_async_callbacks gadget op')
suggest a common way to avoid such kind of issue.

this change implment the callback in dwc3 and
change related functions which have callback to usb gadget driver.

Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Linyu Yuan <linyyuan@codeaurora.org>
Link: https://lore.kernel.org/r/20210629015118.7944-1-linyyuan@codeaurora.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# d0088908 08-Jun-2021 Marian-Cristian Rotariu <marian.c.rotariu@gmail.com>

usb: dwc3: ep0: fix NULL pointer exception

There is no validation of the index from dwc3_wIndex_to_dep() and we might
be referring a non-existing ep and trigger a NULL pointer exception. In
certain configurations we might use fewer eps and the index might wrongly
indicate a larger ep index than existing.

By adding this validation from the patch we can actually report a wrong
index back to the caller.

In our usecase we are using a composite device on an older kernel, but
upstream might use this fix also. Unfortunately, I cannot describe the
hardware for others to reproduce the issue as it is a proprietary
implementation.

[ 82.958261] Unable to handle kernel NULL pointer dereference at virtual address 00000000000000a4
[ 82.966891] Mem abort info:
[ 82.969663] ESR = 0x96000006
[ 82.972703] Exception class = DABT (current EL), IL = 32 bits
[ 82.978603] SET = 0, FnV = 0
[ 82.981642] EA = 0, S1PTW = 0
[ 82.984765] Data abort info:
[ 82.987631] ISV = 0, ISS = 0x00000006
[ 82.991449] CM = 0, WnR = 0
[ 82.994409] user pgtable: 4k pages, 39-bit VAs, pgdp = 00000000c6210ccc
[ 83.000999] [00000000000000a4] pgd=0000000053aa5003, pud=0000000053aa5003, pmd=0000000000000000
[ 83.009685] Internal error: Oops: 96000006 [#1] PREEMPT SMP
[ 83.026433] Process irq/62-dwc3 (pid: 303, stack limit = 0x000000003985154c)
[ 83.033470] CPU: 0 PID: 303 Comm: irq/62-dwc3 Not tainted 4.19.124 #1
[ 83.044836] pstate: 60000085 (nZCv daIf -PAN -UAO)
[ 83.049628] pc : dwc3_ep0_handle_feature+0x414/0x43c
[ 83.054558] lr : dwc3_ep0_interrupt+0x3b4/0xc94

...

[ 83.141788] Call trace:
[ 83.144227] dwc3_ep0_handle_feature+0x414/0x43c
[ 83.148823] dwc3_ep0_interrupt+0x3b4/0xc94
[ 83.181546] ---[ end trace aac6b5267d84c32f ]---

Signed-off-by: Marian-Cristian Rotariu <marian.c.rotariu@gmail.com>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20210608162650.58426-1-marian.c.rotariu@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# fa27e2f6 22-Oct-2020 Thinh Nguyen <Thinh.Nguyen@synopsys.com>

usb: dwc3: ep0: Fix delay status handling

If we want to send a control status on our own time (through
delayed_status), make sure to handle a case where we may queue the
delayed status before the host requesting for it (when XferNotReady
is generated). Otherwise, the driver won't send anything because it's
not EP0_STATUS_PHASE yet. To resolve this, regardless whether
dwc->ep0state is EP0_STATUS_PHASE, make sure to clear the
dwc->delayed_status flag if dwc3_ep0_send_delayed_status() is called.
The control status can be sent when the host requests it later.

Cc: <stable@vger.kernel.org>
Fixes: d97c78a1908e ("usb: dwc3: gadget: END_TRANSFER before CLEAR_STALL command")
Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>


# ae7e8610 28-Sep-2020 Wesley Cheng <wcheng@codeaurora.org>

usb: dwc3: Stop active transfers before halting the controller

In the DWC3 databook, for a device initiated disconnect or bus reset, the
driver is required to send dependxfer commands for any pending transfers.
In addition, before the controller can move to the halted state, the SW
needs to acknowledge any pending events. If the controller is not halted
properly, there is a chance the controller will continue accessing stale or
freed TRBs and buffers.

Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>
Reviewed-by: Thinh Nguyen <thinhn@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>


# 66706077 24-Sep-2020 Thinh Nguyen <Thinh.Nguyen@synopsys.com>

usb: dwc3: ep0: Fix ZLP for OUT ep0 requests

The current ZLP handling for ep0 requests is only for control IN
requests. For OUT direction, DWC3 needs to check and setup for MPS
alignment.

Usually, control OUT requests can indicate its transfer size via the
wLength field of the control message. So usb_request->zero is usually
not needed for OUT direction. To handle ZLP OUT for control endpoint,
make sure the TRB is MPS size.

Cc: stable@vger.kernel.org
Fixes: c7fcdeb2627c ("usb: dwc3: ep0: simplify EP0 state machine")
Fixes: d6e5a549cc4d ("usb: dwc3: simplify ZLP handling")
Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>


# e81a7018 20-Aug-2020 Peter Chen <peter.chen@nxp.com>

usb: dwc3: allocate gadget structure dynamically

The current code uses commit fac323471df6 ("usb: udc: allow adding
and removing the same gadget device") as the workaround to let
the gadget device is re-used, but it is not allowed from driver
core point. In this commit, we allocate gadget structure dynamically,
and free it at its release function. Since the gadget device's
driver_data has already occupied by usb_composite_dev structure, we have
to use gadget device's platform data to store dwc3 structure.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>


# c64b475b 13-Aug-2020 Felipe Balbi <balbi@kernel.org>

usb: dwc3: ep0: fix checkpatch warnings

no functional changes

Signed-off-by: Felipe Balbi <balbi@kernel.org>


# d97c78a1 02-Sep-2020 Thinh Nguyen <Thinh.Nguyen@synopsys.com>

usb: dwc3: gadget: END_TRANSFER before CLEAR_STALL command

According the programming guide (for all DWC3 IPs), when the driver
handles ClearFeature(halt) request, it should issue CLEAR_STALL command
_after_ the END_TRANSFER command completes. The END_TRANSFER command may
take some time to complete. So, delay the ClearFeature(halt) request
control status stage and wait for END_TRANSFER command completion
interrupt. Only after END_TRANSFER command completes that the driver
may issue CLEAR_STALL command.

Cc: stable@vger.kernel.org
Fixes: cb11ea56f37a ("usb: dwc3: gadget: Properly handle ClearFeature(halt)")
Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>


# 10623b87 11-Jul-2020 Alexander A. Klimov <grandmaster@al2klimov.de>

usb: dwc3: Replace HTTP links with HTTPS ones

Rationale:
Reduces attack surface on kernel devs opening the links for MITM
as HTTPS traffic is much harder to manipulate.

Deterministic algorithm:
For each file:
If not .svg:
For each line:
If doesn't contain `\bxmlns\b`:
For each link, `\bhttp://[^# \t\r\n]*(?:\w|/)`:
If neither `\bgnu\.org/license`, nor `\bmozilla\.org/MPL\b`:
If both the HTTP and HTTPS versions
return 200 OK and serve the same content:
Replace HTTP with HTTPS.

Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
Link: https://lore.kernel.org/r/20200711135804.19735-1-grandmaster@al2klimov.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 62fb45d3 18-Jun-2020 Greg Kroah-Hartman <gregkh@linuxfoundation.org>

USB: ch9: add "USB_" prefix in front of TEST defines

For some reason, the TEST_ defines in the usb/ch9.h files did not have
the USB_ prefix on it, making it a bit confusing when reading the file,
as well as not the nicest thing to do in a uapi file.

So fix that up and add the USB_ prefix on to them, and fix up all
in-kernel usages. This included deleting the duplicate copy in the
net2272.h file.

Cc: Felipe Balbi <balbi@kernel.org>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Mathias Nyman <mathias.nyman@intel.com>
Cc: Pawel Laszczak <pawell@cadence.com>
Cc: YueHaibing <yuehaibing@huawei.com>
Cc: Nathan Chancellor <natechancellor@gmail.com>
Cc: Jason Yan <yanaijie@huawei.com>
Cc: Jia-Ju Bai <baijiaju1990@gmail.com>
Cc: Stephen Boyd <swboyd@chromium.org>
Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Jules Irenge <jbi.octave@gmail.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Cc: Rob Gill <rrobgill@protonmail.com>
Cc: Macpaul Lin <macpaul.lin@mediatek.com>
Acked-by: Minas Harutyunyan <hminas@synopsys.com>
Acked-by: Bin Liu <b-liu@ti.com>
Acked-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Acked-by: Peter Chen <peter.chen@nxp.com>
Link: https://lore.kernel.org/r/20200618144206.2655890-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# c58d8bfc 18-Dec-2019 Thinh Nguyen <Thinh.Nguyen@synopsys.com>

usb: dwc3: gadget: Check END_TRANSFER completion

While the END_TRANSFER command is sent but not completed, any request
dequeue during this time will cause the driver to issue the END_TRANSFER
command. The driver needs to submit the command only once to stop the
controller from processing further. The controller may take more time to
process the same command multiple times unnecessarily. Let's add a flag
DWC3_EP_END_TRANSFER_PENDING to check for this condition.

Fixes: 3aec99154db3 ("usb: dwc3: gadget: remove DWC3_EP_END_TRANSFER_PENDING")
Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 2d7b78f5 27-Nov-2019 Thinh Nguyen <Thinh.Nguyen@synopsys.com>

usb: dwc3: ep0: Clear started flag on completion

Clear ep0's DWC3_EP_TRANSFER_STARTED flag if the END_TRANSFER command is
completed. Otherwise, we can't start control transfer again after
END_TRANSFER.

Cc: stable@vger.kernel.org
Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>


# 729dcffd 09-May-2019 Anurag Kumar Vulisha <anurag.kumar.vulisha@xilinx.com>

usb: dwc3: gadget: Add support for disabling U1 and U2 entries

Gadget applications may have a requirement to disable the U1 and U2
entry based on the usecase. Below are few usecases where the disabling
U1/U2 entries may be possible.

Usecase 1:
When combining dwc3 with an redriver for a USB Type-C device solution, it
sometimes have problems with leaving U1/U2 for certain hosts, resulting in
link training errors and reconnects. For this U1/U2 state entries may be
avoided.

Usecase 2:
When performing performance benchmarking on mass storage gadget the
U1 and U2 entries can be disabled.

Usecase 3:
When periodic transfers like ISOC transfers are used with bInterval
of 1 which doesn't require the link to enter into U1 or U2 state entry
(since ping is issued from host for every uframe interval). In this
case the U1 and U2 entry can be disabled.

Disablement of U1/U2 can be done by setting U1DevExitLat and U2DevExitLat
values to 0 in the BOS descriptor. Host on seeing 0 value for U1DevExitLat
and U2DevExitLat, it doesn't send SET_SEL requests to the gadget. There
may be some hosts which may send SET_SEL requests even after seeing 0 in
the UxDevExitLat of BOS descriptor. To aviod U1/U2 entries for these type
of hosts, dwc3 controller can be programmed to reject those U1/U2 requests
by not enabling ACCEPTUxENA bits in DCTL register.

This patch updates the same.

Signed-off-by: Anurag Kumar Vulisha <anurag.kumar.vulisha@xilinx.com>
Signed-off-by: Claus H. Stovgaard <cst@phaseone.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 9566a7c7 13-Jul-2018 Colin Ian King <colin.king@canonical.com>

usb: dwc3: gadget: remove redundant variable maxpacket

Variable maxpacket is being assigned but is never used hence it is
redundant and can be removed.

Cleans up clang warning:
warning: variable 'maxpacket' set but not used [-Wunused-but-set-variable]

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# db9fc500 13-Jul-2018 Colin Ian King <colin.king@canonical.com>

usb: dwc3: gadget: remove redundant variable maxpacket

Variable maxpacket is being assigned but is never used hence it is
redundant and can be removed.

Cleans up clang warning:
warning: variable 'maxpacket' set but not used [-Wunused-but-set-variable]

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# d7ca7e18 10-Apr-2018 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: gadget: initialize transfer index from send_gadget_ep_cmd()

Instead of *always* calling dwc3_gadget_ep_get_transfer_index() after
sending a Start Transfer command, we can call it once from
dwc3_send_gadget_ep_cmd() itself.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 4439661d 10-Apr-2018 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: gadget: assign resource_index inside get_transfer_index()

Instead of returning resource index number just to assign it to a
field inside 'dep' which was passed as argument, we can assing
dep->resource_index from inside dwc3_gadget_ep_get_transfer_index()
itself.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 5f2e7975 29-Mar-2018 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: gadget: remove DWC3_EP_BUSY flag

It has no use anymore.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 7642d838 18-Mar-2018 Heinrich Schuchardt <xypron.glpk@gmx.de>

usb: dwc3: ep0: remove redundant assignment

In

dwc3_request *r = NULL;
r = A;

the first assignment has no effect. Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# f035d139 12-Jan-2018 Thinh Nguyen <Thinh.Nguyen@synopsys.com>

usb: dwc3: ep0: Reset TRB counter for ep0 IN

DWC3 tracks TRB counter for each ep0 direction separately. In control
read transfer completion handler, the driver needs to reset the TRB
enqueue counter for ep0 IN direction. Currently the driver only resets
the TRB counter for control OUT endpoint. Check for the data direction
and properly reset the TRB counter from correct control endpoint.

Cc: stable@vger.kernel.org
Fixes: c2da2ff00606 ("usb: dwc3: ep0: don't use ep0in for transfers")
Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 19e0b203 13-Nov-2017 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: ep0: use gadget->isoch_delay for isoch_delay value

Instead of keeping our own isoch_delay, let's make use of the newly
introduced isoch_delay member in struct usb_gadget. The benefit here
is that we would be using a generic "API" which other UDCs can use,
resulting in a common setup for gadget drivers who may be interested
in Isoch Delay value.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# b5ea4757 06-Nov-2017 Greg Kroah-Hartman <gregkh@linuxfoundation.org>

USB: dwc3: Remove redundant license text

Now that the SPDX tag is in all USB files, that identifies the license
in a specific and legally-defined manner. So the extra GPL text wording
can be removed as it is no longer needed at all.

This is done on a quest to remove the 700+ different ways that files in
the kernel describe the GPL license text. And there's unneeded stuff
like the address (sometimes incorrect) for the FSF which is never
needed.

No copyright headers or other non-license-description text was removed.

Cc: Kukjin Kim <kgene@kernel.org>
Cc: Krzysztof Kozlowski <krzk@kernel.org>
Cc: Patrice Chotard <patrice.chotard@st.com>
Acked-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 5fd54ace 03-Nov-2017 Greg Kroah-Hartman <gregkh@linuxfoundation.org>

USB: add SPDX identifiers to all remaining files in drivers/usb/

It's good to have SPDX identifiers in all files to make it easier to
audit the kernel tree for correct licenses.

Update the drivers/usb/ and include/linux/usb* files with the correct
SPDX license identifier based on the license text in the file itself.
The SPDX identifier is a legally binding shorthand, which can be used
instead of the full boiler plate text.

This work is based on a script and data from Thomas Gleixner, Philippe
Ombredanne, and Kate Stewart.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Cc: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Acked-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 86763723 13-Oct-2017 Christos Gkekas <chris.gekas@gmail.com>

usb: dwc3: ep0: Clean up unused variables

Many variables in ep0 are set but never used, so should be removed.

Signed-off-by: Christos Gkekas <chris.gekas@gmail.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 55168470 11-Sep-2017 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: ep0: fix DMA starvation by assigning req->trb on ep0

If we don't assign a TRB to ep0 requests, we won't be able to unmap
the request later on resulting in starvation of DMA resources.

Fixes: 4a71fcb8ac5f ("usb: dwc3: gadget: only unmap requests from DMA if mapped")
Reported-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Tested-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 9b0a1f95 08-Jun-2017 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: ep0: make sure wValue is 0 on GetStatus()

We don't (yet) support PTM_STATUS messages so let's not reply to them
erroneously.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# bfad65ee 19-Apr-2017 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: update documentation

No functional changes, just making sure we can use these for ReST docs
later.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# d6e5a549 07-Apr-2017 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: simplify ZLP handling

It's much simpler to just add one extra TRB chained to previous TRB to
handle ZLP. This helps us reduce pointless allocations and simplifies
the code a little bit.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 4199c5f8 07-Apr-2017 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: ep0: improve handling of unaligned OUT requests

Just like we did for all other endpoint types, let's rely on a chained
TRB pointing to ep0_bounce_addr in order to align transfer size. This
will make the code simpler.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# d686a5ff 07-Apr-2017 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: ep0: pass dep as argument to internal functions

Instead of constantly recomputing how dwc and epnum relate to dep,
just pass dep as argument.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 7d5e650a 07-Apr-2017 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: ep0: use immediate SETUP on TRB

If we pass TRB's own address on bpl/bph fields, we can get our SETUP
packet as immediate data on the TRB itself, without having to allocate
extra memory for it.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 53896798 14-Jan-2017 Baolin Wang <baolin.wang@linaro.org>

usb: dwc3: ep0: Fix the possible missed request for handling delay STATUS phase

When handing the SETUP packet by composite_setup(), we will release the
dwc->lock. If we get the 'USB_GADGET_DELAYED_STATUS' result from setup
function, which means we need to delay handling the STATUS phase.

But during the lock release period, maybe the request for handling delay
STATUS phase has been queued into list before we set 'dwc->delayed_status'
flag or entering 'EP0_STATUS_PHASE' phase, then we will miss the chance
to handle the STATUS phase. Thus we should check if the request for delay
STATUS phase has been enqueued when entering 'EP0_STATUS_PHASE' phase in
dwc3_ep0_xfernotready(), if so, we should handle it.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 19ec3123 20-Dec-2016 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: ep0: explicitly call dwc3_ep0_prepare_one_trb()

Let's call dwc3_ep0_prepare_one_trb() explicitly
because there are occasions where we will need more
than one TRB to handle an EP0 transfer.

A follow-up patch will fix one bug related to
multiple-TRB Data Phases when it comes to
mapping/unmapping requests for DMA.

Cc: <stable@vger.kernel.org>
Reported-by: Janusz Dziedzic <januszx.dziedzic@linux.intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 7931ec86 20-Dec-2016 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: ep0: add dwc3_ep0_prepare_one_trb()

For now this is just a cleanup patch, no functional
changes. We will be using the new function to fix a
bug introduced long ago by commit 0416e494ce7d
("usb: dwc3: ep0: correct cache sync issue in case
of ep0_bounced") and further worsened by commit
c0bd5456a470 ("usb: dwc3: ep0: handle non maxpacket
aligned transfers > 512")

Cc: <stable@vger.kernel.org>
Reported-by: Janusz Dziedzic <januszx.dziedzic@linux.intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# d64ff406 17-Nov-2016 Arnd Bergmann <arnd@arndb.de>

usb: dwc3: use bus->sysdev for DMA configuration

The dma ops for dwc3 devices are not set properly. So, use a
physical device sysdev, which will be inherited from parent,
to set the hardware / firmware parameters like dma.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Sriram Dash <sriram.dash@nxp.com>
Tested-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 1c404b51 16-Nov-2016 Arnd Bergmann <arnd@arndb.de>

usb: dwc3: ep0: avoid empty-body warning

Building with W=1, we get a warning about harmless empty statements:

drivers/usb/dwc3/ep0.c: In function 'dwc3_ep0_handle_intf':
drivers/usb/dwc3/ep0.c:491:4: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]

Instead of adding empty braces which would introduce checkpatch.pl
warnings, we're just removing the code which doesn't do anything and
making sure we return 0 so USBCV tool is happy.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 5eb30ced 03-Nov-2016 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: trace: purge dwc3_trace()

Finally get rid of dwc3_trace() hack. If any other
message is truly needed, we should add proper
tracepoints for them instead of hacking around with
dwc3_trace() or similar.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# bb014736 14-Oct-2016 Baolin Wang <baolin.wang@linaro.org>

usb: dwc3: gadget: don't clear RUN/STOP when it's invalid to do so

When we change the USB function with configfs dynamically, we possibly
met this situation: one core is doing the control transfer, another core
is trying to unregister the USB gadget from userspace, we must wait for
completing this control tranfer, or it will hang the controller to set
the DEVCTRLHLT flag.

[ felipe.balbi@linux.intel.com: several fixes to the patch
- call complete() before starting following SETUP transfer
- add a macro for ep0_in_setup's timeout
- change commit subject slightly
- break lines at 72 characters (git adds an 8-character tab)
- avoid changes to dwc3_gadget_run_stop() ]

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 39e07ffb 02-Oct-2016 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: ep0: simplify dwc3_ep0_handle_feature()

By extracting smaller functions from
dwc3_ep0_handle_feature(), it becomes far easier to
understand what's going on. Cleanup only, no
functional changes.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 43c96be1 26-Sep-2016 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: trace: print out ep0state also from XferComplete

With this extra piece of information, it will be
easier to find mismatches between driver and HW.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# cdd72ac2 26-Sep-2016 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: debug: move dwc3_ep0_state_string() to debug.h

We will be using dwc3_ep0_state_string() from within
our tracepoints, so we need to move that helper to
debug.h in order for it to be accessible.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 8566cd1a 26-Sep-2016 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: gadget: remove redundant trace prints

Removing some trace prints which were made redundant
when we started decoding events and TRBs completely
within their respective trace points.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 60cfb37a 24-May-2016 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: remove trailing newline from dwc3_trace

when passing strings to trace, we don't need the
trailing newline character. Trace already appends a
newline character automatically.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 501058ed 23-May-2016 John Youn <johnyoun@synopsys.com>

usb: dwc3: ep0: Use the correct type for SET_SEL data

u2sel and u2pel should be __le16. Doesn't fix any issue.

Found with sparse.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 958b9fa7 23-May-2016 John Youn <johnyoun@synopsys.com>

usb: dwc3: ep0: Fix endianness of wIndex passed to dwc3_wIndex_to_dep

The wIndex passed in here is CPU endianness, but the function expects
little endian.

Found with sparse.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# f75cacc4 23-May-2016 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: trace: fully decode IRQ events

This will make it more human-friendly to read trace
output from dwc3.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 2eb88016 12-Apr-2016 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: gadget: add a pointer to endpoint registers

By adding a pointer to endpoint registers' base
address, we can avoid using our controller-wide
struct dwc3 pointer for everything. At some point
this will allow us to have per-endpoint locks which
will, in turn, let us queue requests to separate
endpoints in parallel.

Because of this change our debugfs interface and io
accessors need to be changed accordingly.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 2cd4718d 12-Apr-2016 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: gadget: pass dep as argument to endpoint command

In all call sites of dwc3_send_gadget_ep_cmd() we
already had a valid dep pointer, so instead of
passing dwc and dep->number, which would be used to
fetch the same pointer we already had, just pass dep
directly.

In other words, we're changing:

struct dwc3_ep *dep = dwc[dep->number];

to just passing struct dwc3_ep *dep as argument.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# ae411413 20-Apr-2016 Fei Yang <fei.yang@intel.com>

usb: dwc3: ep0: sanity check test mode selector

In case host sends us an unsupported test mode, we
*must* stall this request. This will tell the host
that the selector is invalid and we won't put the
controller in unsupported test modes which could
have undetermined side-effects.

Signed-off-by: Fei Yang <fei.yang@intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# 53fd8818 04-Apr-2016 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: gadget: rename busy/free_slot to trb_enqueue/dequeue

This makes it clear that we're dealing with a queue
of TRBs. No functional changes. While at that, also
rename start_slot to first_trb_index for similar
reasons.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# aa3342c8 14-Mar-2016 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: better name for our request management lists

request_list and req_queued were, well, weird naming
choices.

Let's give those better names and call them,
respectively, pending_list and started_list. These
new names better reflect what these lists are
supposed to do.

While at that also rename req->queued to req->started.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# bc508161 04-Feb-2016 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: dwc3: drop FIFO resizing logic

That FIFO resizing logic was added to support OMAP5
ES1.0 which had a bogus default FIFO size. I can't
remember the exact size of default FIFO, but it was
less than one bulk superspeed packet (<1024) which
would prevent USB3 from ever working on OMAP5 ES1.0.

However, OMAP5 ES1.0 support has been dropped by
commit aa2f4b16f830 ("ARM: OMAP5: id: Remove ES1.0
support") which renders FIFO resizing unnecessary.

Tested-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# ee5cd41c 05-Feb-2016 John Youn <John.Youn@synopsys.com>

usb: dwc3: Update speed checks for SuperSpeedPlus

Update various places where the speed is checked so that it takes into
account SuperSpeedPlus properly.

Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>


# c4509601 16-Feb-2016 John Youn <John.Youn@synopsys.com>

usb: dwc3: Fix assignment of EP transfer resources

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: <stable@vger.kernel.org> # v3.2+
Reported-by: Ravi Babu <ravibabu@ti.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>


# b5d335e5 16-Nov-2015 Felipe Balbi <balbi@ti.com>

usb: dwc3: ep0: fix setup_packet_pending initialization

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 <balbi@ti.com>


# acc38c49 16-Nov-2015 Felipe Balbi <balbi@ti.com>

usb: dwc3: ep0: purge dev_dbg() calls

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 <balbi@ti.com>


# c0bd5456 26-Jul-2015 Kishon Vijay Abraham I <kishon@ti.com>

usb: dwc3: ep0: handle non maxpacket aligned transfers > 512

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 <kishon@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 2abd9d5f 26-Jul-2015 Kishon Vijay Abraham I <kishon@ti.com>

usb: dwc3: ep0: Add chained TRB support

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 <kishon@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 368ca113 26-Jul-2015 Kishon Vijay Abraham I <kishon@ti.com>

usb: dwc3; ep0: Modify _dwc3_ep0_start_trans_ API to take 'chain' parameter

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 <kishon@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 8a344220 26-Jul-2015 Kishon Vijay Abraham I <kishon@ti.com>

usb: dwc3: ep0: preparation for handling non maxpacket aligned transfers > 512

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 <kishon@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 2e5464da 26-Jul-2015 Kishon Vijay Abraham I <kishon@ti.com>

usb: dwc3: ep0: use _roundup_ to calculate the transfer size

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 <kishon@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# b2fb5b1a 26-Jul-2015 Kishon Vijay Abraham I <kishon@ti.com>

usb: dwc3: ep0: Fix mem corruption on OUT transfers of more than 512 bytes

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: <stable@vger.kernel.org> # 3.4+
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# aebda618 17-Sep-2001 John Youn <John.Youn@synopsys.com>

usb: dwc3: Reset the transfer resource index on SET_INTERFACE

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 <ray.huang@amd.com>
Tested-by: Subbaraya Sundeep Bhatta <subbaraya.sundeep.bhatta@xilinx.com>
Fixes: b23c843992b6 (usb: dwc3: gadget: fix DEPSTARTCFG for non-EP0 EPs)
Cc: <stable@vger.kernel.org> # v3.2+
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# bcdea503 28-Jan-2015 Peter Chen <peter.chen@freescale.com>

usb: dwc3: gadget: use common is_selfpowered

Delete private selfpowered variable, and use common one.

Signed-off-by: Peter Chen <peter.chen@freescale.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 520fe763 10-Nov-2014 Felipe Balbi <balbi@ti.com>

usb: dwc3: ep0: fix for dead code

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 <davej@redhat.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 5eb125b5 03-Nov-2014 Jingoo Han <jg1.han@samsung.com>

usb: dwc3: ep0: remove unnecessary break after return

Fix the following checkpatch warning.

WARNING: break is not useful after a goto or return

Signed-off-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# ccb072de 30-Sep-2014 Felipe Balbi <balbi@ti.com>

usb: dwc3: ep0: trace ep0 TRBs too

Add TRB tracepoints for ep0 TRBs as that
might help finding bugs with ep0 handling.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# dab716cd 24-Sep-2014 Felipe Balbi <balbi@ti.com>

usb: dwc3: trace: remove unnecessary newline character

tracing infrastructure already adds those for us.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 36f84ffb 30-Sep-2014 Felipe Balbi <balbi@ti.com>

usb: dwc3: ep0: fix Data Phase for transfer sizes aligned to wMaxPacketSize

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 <balbi@ti.com>


# 6856d30c 30-Sep-2014 Felipe Balbi <balbi@ti.com>

usb: dwc3: ep0: return early on NULL requests

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 <balbi@ti.com>


# 7a608559 24-Sep-2014 Felipe Balbi <balbi@ti.com>

usb: dwc3: gadget: fix set_halt() bug with pending transfers

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: <stable@vger.kernel.org> # v3.2+
Suggested-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 33fb691b 24-Sep-2014 Felipe Balbi <balbi@ti.com>

usb: dwc3: ep0: hold our lock in dwc3_gadget_ep0_set_halt

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 <balbi@ti.com>


# 2c4cbe6e5 30-Apr-2014 Felipe Balbi <balbi@ti.com>

usb: dwc3: add tracepoints to aid debugging

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 <paulz@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 80977dc9 19-Aug-2014 Felipe Balbi <balbi@ti.com>

usb: dwc3: move all string helper functions to debug.h

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 <balbi@ti.com>


# a535d81c 31-Oct-2013 Alan Stern <stern@rowland.harvard.edu>

usb: dwc3: fix implementation of endpoint wedge

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 <stern@rowland.harvard.edu>
Tested-by: Pratyush Anand <pratyush.anand@st.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 2b84f92b 08-Oct-2013 Joe Perches <joe@perches.com>

usb: Remove unnecessary semicolons

These aren't necessary after switch and if blocks.

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 7c81290e 21-Jul-2013 Felipe Balbi <balbi@ti.com>

usb: dwc3: ep0: don't change to configured state too early

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 <stern@rowland.harvard.edu>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 7a42d835 21-Jul-2013 Felipe Balbi <balbi@ti.com>

usb: dwc3: ep0: only change to ADDRESS if set_config() succeeds

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 <stern@rowland.harvard.edu>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 5945f789 30-Jun-2013 Felipe Balbi <balbi@ti.com>

usb: dwc3: switch to GPL v2 only

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 <av.tikhomirov@samsung.com>
Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# fdba5aa5 25-Jan-2013 Felipe Balbi <balbi@ti.com>

usb: dwc3: remove our homebrew state mechanism

We can reuse the generic implementation via
our struct usb_gadget.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 14cd592f 19-Dec-2011 Felipe Balbi <balbi@ti.com>

usb: dwc3: gadget: implement gadget state tracking

make use of the previously introduced gadget->state
field.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# c390b036 08-Mar-2013 Andrew Morton <akpm@linux-foundation.org>

usb: dwc3: ep0: fix sparc64 build

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 <gregkh@linuxfoundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 0416e494 10-Aug-2012 Pratyush Anand <pratyush.anand@gmail.com>

usb: dwc3: ep0: correct cache sync issue in case of ep0_bounced

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: <stable@vger.kernel.org> # v3.4 v3.5
Signed-off-by: Pratyush Anand <pratyush.anand@st.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 2dfe37d4 23-Jul-2012 Felipe Balbi <balbi@ti.com>

usb: dwc3: ep0: make sure to reinitilize ep1 on STALL

When issuing SetStall on ep0, we must make sure to
reinitialize all flags on physical ep1 too.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 7125d584 19-Jul-2012 Felipe Balbi <balbi@ti.com>

usb: dwc3: ep0: fix status phase delayed status direction

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 <balbi@ti.com>


# 2e3db064 19-Jul-2012 Felipe Balbi <balbi@ti.com>

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>


# fca8892a 19-Jul-2012 Felipe Balbi <balbi@ti.com>

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>


# 77fa6df8 23-Jul-2012 Felipe Balbi <balbi@ti.com>

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>


# 4635d3f2 18-Jul-2012 Felipe Balbi <balbi@ti.com>

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>


# d9b33c60 18-Jul-2012 Felipe Balbi <balbi@ti.com>

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>


# 35f75696 18-Jul-2012 Felipe Balbi <balbi@ti.com>

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>


# e274a31e 01-Jul-2012 Pratyush Anand <pratyush.anand@gmail.com>

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>


# 08f0d966 25-Jun-2012 Pratyush Anand <pratyush.anand@gmail.com>

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>


# 5c81abab 25-Jun-2012 Felipe Balbi <balbi@ti.com>

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>


# b4996a86 05-Jun-2012 Felipe Balbi <balbi@ti.com>

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>


# 85a78101 30-May-2012 Felipe Balbi <balbi@ti.com>

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>


# c8cf7af4 31-May-2012 Felipe Balbi <balbi@ti.com>

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>


# ef21ede6 31-May-2012 Felipe Balbi <balbi@ti.com>

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>


# 33b84c2c 21-May-2012 Felipe Balbi <balbi@ti.com>

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>


# 788a23f4 21-May-2012 Felipe Balbi <balbi@ti.com>

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>


# c74c6d4a 04-May-2012 Felipe Balbi <balbi@ti.com>

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>


# a0807881 04-May-2012 Felipe Balbi <balbi@ti.com>

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>


# 4552a0ca 24-May-2012 Felipe Balbi <balbi@ti.com>

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>


# 16e78db7 12-Mar-2012 Ido Shayevitz <idos@codeaurora.org>

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>


# c12a0d86 25-Apr-2012 Felipe Balbi <balbi@ti.com>

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>


# 865e09e7 24-Apr-2012 Felipe Balbi <balbi@ti.com>

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>


# e6a3b5e2 13-Sep-2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

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>


# ecb07797 16-Mar-2012 Gerard Cauvy <g-cauvy1@ti.com>

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>


# cd423dd3 21-Mar-2012 Felipe Balbi <balbi@ti.com>

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>


# 566ccdda 13-Mar-2012 Moiz Sonasath <m-sonasath@ti.com>

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>


# c2df85ca 24-Feb-2012 Paul Zimmerman <Paul.Zimmerman@synopsys.com>

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>


# 1d046793 15-Feb-2012 Paul Zimmerman <Paul.Zimmerman@synopsys.com>

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>


# 0fc9a1be 19-Dec-2011 Felipe Balbi <balbi@ti.com>

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>


# f6bafc6a 06-Feb-2012 Felipe Balbi <balbi@ti.com>

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>


# 3b637367 09-Feb-2012 Gerard Cauvy <g-cauvy1@ti.com>

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>


# 457e84b6 18-Jan-2012 Felipe Balbi <balbi@ti.com>

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>


# bb5cfd68 18-Jan-2012 Felipe Balbi <balbi@ti.com>

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>


# 04a9bfcd 02-Jan-2012 Felipe Balbi <balbi@ti.com>

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>


# 1a0955fe 10-Jan-2012 Felipe Balbi <balbi@ti.com>

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>


# 68d8a781 28-Dec-2011 Felipe Balbi <balbi@ti.com>

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>


# 68d3e668 08-Dec-2011 Felipe Balbi <balbi@ti.com>

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>


# e2617796 29-Nov-2011 Felipe Balbi <balbi@ti.com>

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>


# e0ce0b0a 24-Nov-2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

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>


# df62df56 14-Oct-2011 Felipe Balbi <balbi@ti.com>

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>


# 5bdb1dcc 02-Nov-2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

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>


# f0f2b2a2 02-Nov-2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

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>


# 8becf270 03-Nov-2011 Felipe Balbi <balbi@ti.com>

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>


# 25b8ff68 03-Nov-2011 Felipe Balbi <balbi@ti.com>

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>


# c2da2ff0 20-Oct-2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

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>


# 1e7618d8 23-Oct-2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

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>


# 8ee6270c 18-Oct-2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

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>


# 0cc7a519 18-Oct-2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

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>


# 9cc9bcd5 18-Oct-2011 Felipe Balbi <balbi@ti.com>

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>


# f96a6ec1 15-Oct-2011 Felipe Balbi <balbi@ti.com>

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>


# dc1c70a7 30-Sep-2011 Felipe Balbi <balbi@ti.com>

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>


# b23c8439 30-Sep-2011 Paul Zimmerman <Paul.Zimmerman@synopsys.com>

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>


# 49a25cc9 30-Sep-2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

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>


# b147f357 30-Sep-2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

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>


# 9876cbe2 30-Sep-2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

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>


# 25355be6 30-Sep-2011 Felipe Balbi <balbi@ti.com>

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>


# d95b09b9 30-Sep-2011 Felipe Balbi <balbi@ti.com>

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>


# 2646021e 30-Sep-2011 Felipe Balbi <balbi@ti.com>

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>


# 55f3fba6 08-Sep-2011 Felipe Balbi <balbi@ti.com>

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>


# d742220b 08-Sep-2011 Felipe Balbi <balbi@ti.com>

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>


# 1ddcb218 30-Aug-2011 Felipe Balbi <balbi@ti.com>

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>


# 0b7836a9 30-Aug-2011 Felipe Balbi <balbi@ti.com>

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>


# 76cb323f 30-Aug-2011 Felipe Balbi <balbi@ti.com>

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>


# b673cf30 31-Aug-2011 Felipe Balbi <balbi@ti.com>

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>


# c7fcdeb2 27-Aug-2011 Felipe Balbi <balbi@ti.com>

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>


# a6829706 27-Aug-2011 Felipe Balbi <balbi@ti.com>

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>


# c611ccb4 26-Aug-2011 Felipe Balbi <balbi@ti.com>

usb: dwc3: ep0: fix 'transfered' typo

trivial patch. No functional changes.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 72246da4 19-Aug-2011 Felipe Balbi <balbi@ti.com>

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>