Synopsys DesignWare Core SuperSpeed USB 3.0 Controller
Author: Felipe Balbi <felipe.balbi@linux.intel.com>
Date: April 2017
Introduction #
The Synopsys DesignWare Core SuperSpeed USB 3.0 Controller (hereinafter referred to as DWC3) is a USB SuperSpeed compliant controller which can be configured in one of 4 ways:
Peripheral-only configuration
Host-only configuration
Dual-Role configuration
Hub configuration
Linux currently supports several versions of this controller. In all likelihood, the version in your SoC is already supported. At the time of this writing, known tested versions range from 2.02a to 3.10a. As a rule of thumb, anything above 2.02a should work reliably well.
Currently, we have many known users for this driver. In alphabetical order:
Cavium
Intel Corporation
Qualcomm
Rockchip
ST
Samsung
Texas Instruments
Xilinx
Summary of Features #
For details about features supported by your version of DWC3, consult your IP team and/or Synopsys DesignWare Core SuperSpeed USB 3.0 Controller Databook. Following is a list of features supported by the driver at the time of this writing:
Up to 16 bidirectional endpoints (including the control pipe - ep0)
Flexible endpoint configuration
Simultaneous IN and OUT transfer support
Scatter-list support
Up to 256 TRBs 1 per endpoint
Support for all transfer types (Control, Bulk, Interrupt, and Isochronous)
SuperSpeed Bulk Streams
Link Power Management
Trace Events for debugging
DebugFS 3 interface
These features have all been exercised with many of the in-tree gadget drivers. We have verified both ConfigFS 4 and legacy gadget drivers.
Driver Design #
The DWC3 driver sits on the drivers/usb/dwc3/ directory. All files related to this driver are in this one directory. This makes it easy for new-comers to read the code and understand how it behaves.
Because of DWC3's configuration flexibility, the driver is a little complex in some places but it should be rather straightforward to understand.
The biggest part of the driver refers to the Gadget API.
Known Limitations #
Like any other HW, DWC3 has its own set of limitations. To avoid constant questions about such problems, we decided to document them here and have a single location to where we could point users.
OUT Transfer Size Requirements #
According to Synopsys Databook, all OUT transfer TRBs 1 must have their size field set to a value which is integer divisible by the endpoint's wMaxPacketSize. This means that e.g. in order to receive a Mass Storage CBW 5, req->length must either be set to a value that's divisible by wMaxPacketSize (1024 on SuperSpeed, 512 on HighSpeed, etc), or DWC3 driver must add a Chained TRB pointing to a throw-away buffer for the remaining length. Without this, OUT transfers will NOT start.
Note that as of this writing, this won't be a problem because DWC3 is fully capable of appending a chained TRB for the remaining length and completely hide this detail from the gadget driver. It's still worth mentioning because this seems to be the largest source of queries about DWC3 and non-working transfers.
TRB Ring Size Limitation #
We, currently, have a hard limit of 256 TRBs 1 per endpoint, with the last TRB being a Link TRB 2 pointing back to the first. This limit is arbitrary but it has the benefit of adding up to exactly 4096 bytes, or 1 Page.
DWC3 driver will try its best to cope with more than 255 requests and, for the most part, it should work normally. However this is not something that has been exercised very frequently. If you experience any problems, see section Reporting Bugs below.
Reporting Bugs #
Whenever you encounter a problem with DWC3, first and foremost you should make sure that:
You're running latest tag from Linus' tree
You can reproduce the error without any out-of-tree changes to DWC3
You have checked that it's not a fault on the host machine
After all these are verified, then here's how to capture enough information so we can be of any help to you.
Required Information #
DWC3 relies exclusively on Trace Events for debugging. Everything is exposed there, with some extra bits being exposed to DebugFS 3.
In order to capture DWC3's Trace Events you should run the following commands before plugging the USB cable to a host machine:
# mkdir -p /d
# mkdir -p /t
# mount -t debugfs none /d
# mount -t tracefs none /t
# echo 81920 > /t/buffer_size_kb
# echo 1 > /t/events/dwc3/enable
After this is done, you can connect your USB cable and reproduce the problem. As soon as the fault is reproduced, make a copy of files trace and regdump, like so:
# cp /t/trace /root/trace.txt
# cat /d/*dwc3*/regdump > /root/regdump.txt
Make sure to compress trace.txt and regdump.txt in a tarball and email it to me with linux-usb in Cc. If you want to be extra sure that I'll help you, write your subject line in the following format:
[BUG REPORT] usb: dwc3: Bug while doing XYZ
On the email body, make sure to detail what you doing, which gadget driver you were using, how to reproduce the problem, what SoC you're using, which OS (and its version) was running on the Host machine.
With all this information, we should be able to understand what's going on and be helpful to you.
Debugging #
First and foremost a disclaimer:
DISCLAIMER: The information available on DebugFS and/or TraceFS can
change at any time at any Major Linux Kernel Release. If writing
scripts, do **NOT** assume information to be available in the
current format.
With that out of the way, let's carry on.
If you're willing to debug your own problem, you deserve a round of applause :-)
Anyway, there isn't much to say here other than Trace Events will be really helpful in figuring out issues with DWC3. Also, access to Synopsys Databook will be really valuable in this case.
A USB Sniffer can be helpful at times but it's not entirely required, there's a lot that can be understood without looking at the wire.
Feel free to email me and Cc linux-usb if you need any help.
DebugFS #
DebugFS is very good for gathering snapshots of what's going on with DWC3 and/or any endpoint.
On DWC3's DebugFS directory, you will find the following files and directories:
ep[0..15]{in,out}/ link_state regdump testmode
link_state #
When read, link_state will print out one of U0, U1, U2, U3, SS.Disabled, RX.Detect, SS.Inactive, Polling, Recovery, Hot Reset, Compliance, Loopback, Reset, Resume or UNKNOWN link state.
This file can also be written to in order to force link to one of the states above.
regdump #
File name is self-explanatory. When read, regdump will print out a register dump of DWC3. Note that this file can be grepped to find the information you want.
testmode #
When read, testmode will print out a name of one of the specified USB 2.0 Testmodes (test_j, test_k, test_se0_nak, test_packet, test_force_enable) or the string no test in case no tests are currently being executed.
In order to start any of these test modes, the same strings can be written to the file and DWC3 will enter the requested test mode.
ep[0..15]{in,out} #
For each endpoint we expose one directory following the naming convention ep$num$dir (ep0in, ep0out, ep1in, ...). Inside each of these directories you will find the following files:
descriptor_fetch_queue event_queue rx_fifo_queue rx_info_queue rx_request_queue transfer_type trb_ring tx_fifo_queue tx_request_queue
With access to Synopsys Databook, you can decode the information on them.
transfer_type #
When read, transfer_type will print out one of control, bulk, interrupt or isochronous depending on what the endpoint descriptor says. If the endpoint hasn't been enabled yet, it will print --.
trb_ring #
When read, trb_ring will print out details about all TRBs on the ring. It will also tell you where our enqueue and dequeue pointers are located in the ring:
Trace Events #
DWC3 also provides several trace events which help us gathering information about the behavior of the driver during runtime.
In order to use these events, you must enable CONFIG_FTRACE in your kernel config.
For details about how enable DWC3 events, see section Reporting Bugs.
The following subsections will give details about each Event Class and each Event defined by DWC3.
MMIO #
It is sometimes useful to look at every MMIO access when looking for bugs. Because of that, DWC3 offers two Trace Events (one for dwc3_readl() and one for dwc3_writel()). TP_printk follows:
TP_printk("addr %p value %08x", __entry->base + __entry->offset,
__entry->value)
Interrupt Events #
Every IRQ event can be logged and decoded into a human readable string. Because every event will be different, we don't give an example other than the TP_printk format used:
TP_printk("event (%08x): %s", __entry->event,
dwc3_decode_event(__entry->event, __entry->ep0state))
Control Request #
Every USB Control Request can be logged to the trace buffer. The output format is:
TP_printk("%s", dwc3_decode_ctrl(__entry->bRequestType,
__entry->bRequest, __entry->wValue,
__entry->wIndex, __entry->wLength)
)
Note that Standard Control Requests will be decoded into human-readable strings with their respective arguments. Class and Vendor requests will be printed out a sequence of 8 bytes in hex format.
Lifetime of a struct usb_request #
The entire lifetime of a struct usb_request can be tracked on the trace buffer. We have one event for each of allocation, free, queueing, dequeueing, and giveback. Output format is:
TP_printk("%s: req %p length %u/%u %s%s%s ==> %d",
__get_str(name), __entry->req, __entry->actual, __entry->length,
__entry->zero ? "Z" : "z",
__entry->short_not_ok ? "S" : "s",
__entry->no_interrupt ? "i" : "I",
__entry->status
)
Generic Commands #
We can log and decode every Generic Command with its completion code. Format is:
TP_printk("cmd '%s' [%x] param %08x --> status: %s",
dwc3_gadget_generic_cmd_string(__entry->cmd),
__entry->cmd, __entry->param,
dwc3_gadget_generic_cmd_status_string(__entry->status)
)
Endpoint Commands #
Endpoints commands can also be logged together with completion code. Format is:
TP_printk("%s: cmd '%s' [%d] params %08x %08x %08x --> status: %s",
__get_str(name), dwc3_gadget_ep_cmd_string(__entry->cmd),
__entry->cmd, __entry->param0,
__entry->param1, __entry->param2,
dwc3_ep_cmd_status_string(__entry->cmd_status)
)
Lifetime of a TRB #
A TRB Lifetime is simple. We are either preparing a TRB or completing it. With these two events, we can see how a TRB changes over time. Format is:
TP_printk("%s: %d/%d trb %p buf %08x%08x size %s%d ctrl %08x (%c%c%c%c:%c%c:%s)",
__get_str(name), __entry->queued, __entry->allocated,
__entry->trb, __entry->bph, __entry->bpl,
({char *s;
int pcm = ((__entry->size >> 24) & 3) + 1;
switch (__entry->type) {
case USB_ENDPOINT_XFER_INT:
case USB_ENDPOINT_XFER_ISOC:
switch (pcm) {
case 1:
s = "1x ";
break;
case 2:
s = "2x ";
break;
case 3:
s = "3x ";
break;
}
default:
s = "";
} s; }),
DWC3_TRB_SIZE_LENGTH(__entry->size), __entry->ctrl,
__entry->ctrl & DWC3_TRB_CTRL_HWO ? 'H' : 'h',
__entry->ctrl & DWC3_TRB_CTRL_LST ? 'L' : 'l',
__entry->ctrl & DWC3_TRB_CTRL_CHN ? 'C' : 'c',
__entry->ctrl & DWC3_TRB_CTRL_CSP ? 'S' : 's',
__entry->ctrl & DWC3_TRB_CTRL_ISP_IMI ? 'S' : 's',
__entry->ctrl & DWC3_TRB_CTRL_IOC ? 'C' : 'c',
dwc3_trb_type_string(DWC3_TRBCTL_TYPE(__entry->ctrl))
)
Lifetime of an Endpoint #
And endpoint's lifetime is summarized with enable and disable operations, both of which can be traced. Format is:
TP_printk("%s: mps %d/%d streams %d burst %d ring %d/%d flags %c:%c%c%c%c%c:%c:%c",
__get_str(name), __entry->maxpacket,
__entry->maxpacket_limit, __entry->max_streams,
__entry->maxburst, __entry->trb_enqueue,
__entry->trb_dequeue,
__entry->flags & DWC3_EP_ENABLED ? 'E' : 'e',
__entry->flags & DWC3_EP_STALL ? 'S' : 's',
__entry->flags & DWC3_EP_WEDGE ? 'W' : 'w',
__entry->flags & DWC3_EP_TRANSFER_STARTED ? 'B' : 'b',
__entry->flags & DWC3_EP_PENDING_REQUEST ? 'P' : 'p',
__entry->flags & DWC3_EP_END_TRANSFER_PENDING ? 'E' : 'e',
__entry->direction ? '<' : '>'
)
Structures, Methods and Definitions #
struct dwc3_event_buffer #
Software event buffer representation
Definition
;
Members
buf: THE buffercache: The buffer cache used in the threaded interruptlength: size of this bufferlpos: event offsetcount: cache of last read event count registerflags: flags related to this event bufferdma: dma_addr_tdwc: pointer to DWC controller
struct dwc3_ep #
device side endpoint representation
Definition
;
Members
endpoint: usb endpointnostream_work: work for handling bulk NoStreamcancelled_list: list of cancelled requests for this endpointpending_list: list of pending requests for this endpointstarted_list: list of started requests on this endpointtrb_pool: array of transaction bufferstrb_pool_dma: dma address of trb_pooldwc: pointer to DWC controllersaved_state: ep state saved during hibernationflags: endpoint flags (wedged, stalled, ...)trb_enqueue: enqueue 'pointer' into TRB arraytrb_dequeue: dequeue 'pointer' into TRB arraynumber: endpoint number (1 - 15)type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASKresource_index: Resource transfer indexframe_number: set to the frame number we want this transfer to start (ISOC)interval: the interval on which the ISOC transfer is startedname: a human readable name e.g. ep1out-bulkdirection: true for TX, false for RXstream_capable: true when streams are enabledcombo_num: the test combination BIT[15:14] of the frame number to test isochronous START TRANSFER command failure workaroundstart_cmd_status: the status of testing START TRANSFER command with combo_num = 'b00
struct dwc3_trb #
transfer request block (hw format)
Definition
;
Members
bpl: DW0-3bph: DW4-7size: DW8-Bctrl: DWC-F
struct dwc3_hwparams #
copy of HWPARAMS registers
Definition
;
Members
hwparams0: GHWPARAMS0hwparams1: GHWPARAMS1hwparams2: GHWPARAMS2hwparams3: GHWPARAMS3hwparams4: GHWPARAMS4hwparams5: GHWPARAMS5hwparams6: GHWPARAMS6hwparams7: GHWPARAMS7hwparams8: GHWPARAMS8hwparams9: GHWPARAMS9
struct dwc3_request #
representation of a transfer request
Definition
;
Members
request: struct usb_request to be transferredlist: a list_head used for request queueingdep: struct dwc3_ep owning this requeststart_sg: pointer to the sg which should be queued nextnum_pending_sgs: counter to pending sgsremaining: amount of data remainingstatus: internal dwc3 request status trackingepnum: endpoint number to which this request referstrb: pointer to struct dwc3_trbtrb_dma: DMA address of trbnum_trbs: number of TRBs used by this requestdirection: IN or OUT direction flagmapped: true when request has been dma-mapped
struct dwc3_glue_ops #
The ops indicate the notifications that need to be passed on to glue layer
Definition
;
Members
pre_set_role: Notify glue of role switch notificationspre_run_stop: Notify run stop enable/disable information to glue
struct dwc3 #
representation of our controller
Definition
;
Members
drd_work: workqueue used for role swappingep0_trb: trb which is used for the ctrl_reqbounce: address of bounce buffersetup_buf: used while precessing STD USB requestsep0_trb_addr: dma address of ep0_trbbounce_addr: dma address of bounceep0_usb_req: dummy req used while handling STD USB requestsep0_in_setup: one control transfer is completed and enter setup phaselock: for synchronizingmutex: for mode switchingdev: pointer to our struct devicesysdev: pointer to the DMA-capable devicexhci: pointer to our xHCI childxhci_resources: struct resources for our xhci childev_buf: struct dwc3_event_buffer pointereps: endpoint arraygadget: device side representation of the peripheral controllergadget_driver: pointer to the gadget driverglue_ops: Vendor callbacks for flattened device implementations.bus_clk: clock for accessing the registersref_clk: reference clocksusp_clk: clock used when the SS phy is in low power (S3) stateutmi_clk: clock used for USB2 PHY communicationpipe_clk: clock used for USB3 PHY communicationreset: reset controlusb2_phy: pointer to USB2 PHYusb3_phy: pointer to USB3 PHYusb2_generic_phy: pointer to array of USB2 PHYsusb3_generic_phy: pointer to array of USB3 PHYsnum_usb2_ports: number of USB2 portsnum_usb3_ports: number of USB3 portsphys_ready: flag to indicate that PHYs are readyulpi: pointer to ulpi interfaceulpi_ready: flag to indicate that ULPI is initializedregs: base address for our registersregs_size: address space sizedr_mode: requested mode of operationcurrent_dr_role: current role of operation when in dual-role modedesired_dr_role: desired role of operation when in dual-role modeedev: extcon handleedev_nb: extcon notifierhsphy_mode: UTMI phy mode, one of following:- USBPHY_INTERFACE_MODE_UTMI
- USBPHY_INTERFACE_MODE_UTMIW
role_sw: usb_role_switch handlerole_switch_default_mode: default operation mode of controller while usb role is USB_ROLE_NONE.usb_psy: pointer to power supply interface.vbus_draw_work: Work to set the vbus drawing limitcurrent_limit: How much current to draw from vbus, in milliAmperes.fladj: frame length adjustmentref_clk_per: reference clock period configurationirq_gadget: peripheral controller's IRQ numberotg_irq: IRQ number for OTG IRQscurrent_otg_role: current role of operation while using the OTG blockdesired_otg_role: desired role of operation while using the OTG blockotg_restart_host: flag that OTG controller needs to restart hostu1u2: only used on revisions <1.83a for workaroundmaximum_speed: maximum speed requested (mainly for testing purposes)gadget_max_speed: maximum gadget speed requestedmax_ssp_rate: SuperSpeed Plus maximum signaling rate and lane countgadget_ssp_rate: Gadget driver's maximum supported SuperSpeed Plus signaling rate and lane count.ip: controller's IDrevision: controller's version of an IPversion_type: VERSIONTYPE register contents, a sub release of a revisionep0_next_event: hold the next expected eventep0state: state of endpoint zerolink_state: link stateu2sel: parameter from Set SEL request.u2pel: parameter from Set SEL request.u1sel: parameter from Set SEL request.u1pel: parameter from Set SEL request.speed: device speed (super, high, full, low)num_eps: number of endpointshwparams: copy of hwparams registersregset: debugfs pointer to regdump filedbg_lsp_select: current debug lsp mux register selectiontest_mode: true when we're entering a USB test modetest_mode_nr: test feature selectorlpm_nyet_threshold: LPM NYET response thresholdhird_threshold: HIRD thresholdrx_thr_num_pkt: USB receive packet countrx_max_burst: max USB receive burst sizetx_thr_num_pkt: USB transmit packet counttx_max_burst: max USB transmit burst sizerx_thr_num_pkt_prd: periodic ESS receive packet countrx_max_burst_prd: max periodic ESS receive burst sizetx_thr_num_pkt_prd: periodic ESS transmit packet counttx_max_burst_prd: max periodic ESS transmit burst sizetx_fifo_resize_max_num: max number of fifos allocated during txfifo resizeclear_stall_protocol: endpoint number that requires a delayed status phasenum_hc_interrupters: number of host controller interruptershsphy_interface: "utmi" or "ulpi"connected: true when we're connected to a host, false otherwisesoftconnect: true when gadget connect is called, false when disconnect runsdelayed_status: true when gadget driver asks for delayed statusep0_bounced: true when we used bounce bufferep0_expect_in: true when we expect a DATA IN transfersysdev_is_parent: true when dwc3 device has a parent driverhas_lpm_erratum: true when core was configured with LPM Erratum. Note that there's now way for software to detect this in runtime.is_utmi_l1_suspend: the core asserts output signal 0 - utmi_sleep_n 1 - utmi_l1_suspend_nis_fpga: true when we are using the FPGA boardpending_events: true when we have pending IRQs to be handleddo_fifo_resize: true when txfifo resizing is enabled for dwc3 endpointspullups_connected: true when Run/Stop bit is setsetup_packet_pending: true when there's a Setup Packet in FIFO. Workaroundthree_stage_setup: set if we perform a three phase setupdis_start_transfer_quirk: set if start_transfer failure SW workaround is not needed for DWC_usb31 version 1.70a-ea06 and belowusb3_lpm_capable: set if hadrware supports Link Power Managementusb2_lpm_disable: set to disable usb2 lpm for hostusb2_gadget_lpm_disable: set to disable usb2 lpm for gadgetdisable_scramble_quirk: set if we enable the disable scramble quirku2exit_lfps_quirk: set if we enable u2exit lfps quirku2ss_inp3_quirk: set if we enable P3 OK for U2/SS Inactive quirkreq_p1p2p3_quirk: set if we enable request p1p2p3 quirkdel_p1p2p3_quirk: set if we enable delay p1p2p3 quirkdel_phy_power_chg_quirk: set if we enable delay phy power change quirklfps_filter_quirk: set if we enable LFPS filter quirkrx_detect_poll_quirk: set if we enable rx_detect to polling lfps quirkdis_u3_susphy_quirk: set if we disable usb3 suspend phydis_u2_susphy_quirk: set if we disable usb2 suspend phydis_enblslpm_quirk: set if we clear enblslpm in GUSB2PHYCFG, disabling the suspend signal to the PHY.dis_u1_entry_quirk: set if link entering into U1 state needs to be disabled.dis_u2_entry_quirk: set if link entering into U2 state needs to be disabled.dis_rxdet_inp3_quirk: set if we disable Rx.Detect in P3dis_u2_freeclk_exists_quirk: set if we clear u2_freeclk_exists in GUSB2PHYCFG, specify that USB2 PHY doesn't provide a free-running PHY clock.dis_del_phy_power_chg_quirk: set if we disable delay phy power change quirk.dis_tx_ipgap_linecheck_quirk: set if we disable u2mac linestate check during HS transmit.resume_hs_terminations: Set if we enable quirk for fixing improper crc generation after resume from suspend.ulpi_ext_vbus_drv: Set to confiure the upli chip to drives CPEN pin VBUS with an external supply.parkmode_disable_ss_quirk: set if we need to disable all SuperSpeed instances in park mode.parkmode_disable_hs_quirk: set if we need to disable all HishSpeed instances in park mode.gfladj_refclk_lpm_sel: set if we need to enable SOF/ITP counter running based on ref_clktx_de_emphasis_quirk: set if we enable Tx de-emphasis quirktx_de_emphasis: Tx de-emphasis value 0 - -6dB de-emphasis 1 - -3.5dB de-emphasis 2 - No de-emphasis 3 - Reserveddis_metastability_quirk: set to disable metastability quirk.dis_split_quirk: set to disable split boundary.async_callbacks: if set, indicate that async callbacks will be used.sys_wakeup: set if the device may do system wakeup.wakeup_configured: set if the device is configured for remote wakeup.suspended: set to track suspend event due to U3/L2.susphy_state: state of DWC3_GUSB2PHYCFG_SUSPHY + DWC3_GUSB3PIPECTL_SUSPHY before PM suspend.imod_interval: set the interrupt moderation interval in 250ns increments or 0 to disable.max_cfg_eps: current max number of IN eps used across all USB configs.last_fifo_depth: last fifo depth used to determine next fifo ram start address.num_ep_resized: carries the current number endpoints which have had its tx fifo resized.debug_root: root debugfs directory for this device to put its files in.gsbuscfg0_reqinfo: store GSBUSCFG0.DATRDREQINFO, DESRDREQINFO, DATWRREQINFO, and DESWRREQINFO value passed from glue driver.wakeup_pending_funcs: Indicates whether any interface has requested for function wakeup in bitmap format where bit position represents interface_id.
struct dwc3_event_depevt #
Device Endpoint Events
Definition
;
Members
one_bit: indicates this is an endpoint event (not used)endpoint_number: number of the endpointendpoint_event: The event we have: 0x00 - Reserved 0x01 - XferComplete 0x02 - XferInProgress 0x03 - XferNotReady 0x04 - RxTxFifoEvt (IN->Underrun, OUT->Overrun) 0x05 - Reserved 0x06 - StreamEvt 0x07 - EPCmdCmpltreserved11_10: Reserved, don't use.status: Indicates the status of the event. Refer to databook for more information.parameters: Parameters of the current event. Refer to databook for more information.
struct dwc3_event_devt #
Device Events
Definition
;
Members
one_bit: indicates this is a non-endpoint event (not used)device_event: indicates it's a device event. Should read as 0x00type: indicates the type of device event. 0 - DisconnEvt 1 - USBRst 2 - ConnectDone 3 - ULStChng 4 - WkUpEvt 5 - Reserved 6 - Suspend (EOPF on revisions 2.10a and prior) 7 - SOF 8 - Reserved 9 - ErrticErr 10 - CmdCmplt 11 - EvntOverflow 12 - VndrDevTstRcvedreserved15_12: Reserved, not usedevent_info: Information about this eventreserved31_25: Reserved, not used
struct dwc3_event_gevt #
Other Core Events
Definition
;
Members
one_bit: indicates this is a non-endpoint event (not used)device_event: indicates it's (0x03) Carkit or (0x04) I2C event.phy_port_number: self-explanatoryreserved31_12: Reserved, not used.
union dwc3_event #
representation of Event Buffer contents
Definition
;
Members
raw: raw 32-bit eventtype: the type of the eventdepevt: Device Endpoint Eventdevt: Device Eventgevt: Global Event
struct dwc3_gadget_ep_cmd_params #
representation of endpoint command parameters
Definition
;
Members
param2: third parameterparam1: second parameterparam0: first parameter
dwc3_mdwidth() #
u32 get MDWIDTH value in bits
Parameters
struct dwc3 *dwc: pointer to our context structure
Description
Return MDWIDTH configuration value in bits.
next_request() #
struct dwc3_request * gets the next request on the given list
Parameters
struct list_head *list: the request list to operate on
Description
Caller should take care of locking. This function return NULL or the first
request available on list.
dwc3_gadget_move_started_request() #
void move req to the started_list
Parameters
struct dwc3_request *req: the request to be moved
Description
Caller should take care of locking. This function will move req from its current list to the endpoint's started_list.
dwc3_gadget_move_cancelled_request() #
void move req to the cancelled_list
Parameters
struct dwc3_request *req: the request to be movedunsigned int reason: cancelled reason for the dwc3 request
Description
Caller should take care of locking. This function will move req from its current list to the endpoint's cancelled_list.
dwc3_gadget_ep_get_transfer_index() #
void Gets transfer index from HW
Parameters
struct dwc3_ep *dep: dwc3 endpoint
Description
Caller should take care of locking. Returns the transfer resource index for a given endpoint.
dwc3_gadget_dctl_write_safe() #
void write to DCTL safe from link state change
Parameters
struct dwc3 *dwc: pointer to our context structureu32 value: value to write to DCTL
Description
Use this function when doing read-modify-write to DCTL. It will not send link state change request.
dwc3_gadget_set_test_mode() #
int enables usb2 test modes
Parameters
struct dwc3 *dwc: pointer to our context structureint mode: the mode to set (J, K SE0 NAK, Force Enable)
Description
Caller should take care of locking. This function will return 0 on success or -EINVAL if wrong Test Selector is passed.
dwc3_gadget_get_link_state() #
int gets current state of usb link
Parameters
struct dwc3 *dwc: pointer to our context structure
Description
Caller should take care of locking. This function will return the link state on success (>= 0) or -ETIMEDOUT.
dwc3_gadget_set_link_state() #
int sets usb link to a particular state
Parameters
struct dwc3 *dwc: pointer to our context structureenum dwc3_link_state state: the state to put link into
Description
Caller should take care of locking. This function will return 0 on success or -ETIMEDOUT.
dwc3_ep_inc_trb() #
void increment a trb index.
Parameters
u8 *index: Pointer to the TRB index to increment.
Description
The index should never point to the link TRB. After incrementing, if it is point to the link TRB, wrap around to the beginning. The link TRB is always at the last TRB entry.
dwc3_ep_inc_enq() #
void increment endpoint's enqueue pointer
Parameters
struct dwc3_ep *dep: The endpoint whose enqueue pointer we're incrementing
dwc3_ep_inc_deq() #
void increment endpoint's dequeue pointer
Parameters
struct dwc3_ep *dep: The endpoint whose enqueue pointer we're incrementing
dwc3_gadget_giveback() #
void call struct usb_request's ->complete callback
Parameters
struct dwc3_ep *dep: The endpoint to whom the request belongs tostruct dwc3_request *req: The request we're giving backint status: completion code for the request
Description
Must be called with controller's lock held and interrupts disabled. This
function will unmap req and call its ->complete() callback to notify upper
layers that it has completed.
dwc3_send_gadget_generic_command() #
int issue a generic command for the controller
Parameters
struct dwc3 *dwc: pointer to the controller contextunsigned int cmd: the command to be issuedu32 param: command parameter
Description
Caller should take care of locking. Issue cmd with a given param to dwc and wait for its completion.
dwc3_send_gadget_ep_cmd() #
int issue an endpoint command
Parameters
struct dwc3_ep *dep: the endpoint to which the command is going to be issuedunsigned int cmd: the command to be issuedstruct dwc3_gadget_ep_cmd_params *params: parameters to the command
Description
Caller should handle locking. This function will issue cmd with given params to dep and wait for its completion.
According to the programming guide, if the link state is in L1/L2/U3, then sending the Start Transfer command may not complete. The programming guide suggested to bring the link state back to ON/U0 by performing remote wakeup prior to sending the command. However, don't initiate remote wakeup when the user/function does not send wakeup request via wakeup ops. Send the command when it's allowed.
Notes
For L1 link state, issuing a command requires the clearing of GUSB2PHYCFG.SUSPENDUSB2, which turns on the signal required to complete the given command (usually within 50us). This should happen within the command timeout set by driver. No additional step is needed.
For L2 or U3 link state, the gadget is in USB suspend. Care should be taken when sending Start Transfer command to ensure that it's done after USB resume.
dwc3_gadget_start_config() #
int reset endpoint resources
Parameters
struct dwc3 *dwc: pointer to the DWC3 contextunsigned int resource_index: DEPSTARTCFG.XferRscIdx value (must be 0 or 2)
Description
Set resource_index=0 to reset all endpoints' resources allocation. Do this as part of the power-on/soft-reset initialization.
Set resource_index=2 to reset only non-control endpoints' resources. Do this on receiving the SET_CONFIGURATION request or hibernation resume.
dwc3_gadget_calc_tx_fifo_size() #
int calculates the txfifo size value
Parameters
struct dwc3 *dwc: pointer to the DWC3 contextint mult: multiplier to be used when calculating the fifo_size
Description
Calculates the size value based on the equation below:
DWC3 revision 280A and prior: fifo_size = mult * (max_packet / mdwidth) + 1;
DWC3 revision 290A and onwards: fifo_size = mult * ((max_packet + mdwidth)/mdwidth + 1) + 1
The max packet size is set to 1024, as the txfifo requirements mainly apply to super speed USB use cases. However, it is safe to overestimate the fifo allocations for other scenarios, i.e. high speed USB.
dwc3_gadget_calc_ram_depth() #
int calculates the ram depth for txfifo
Parameters
struct dwc3 *dwc: pointer to the DWC3 context
dwc3_gadget_clear_tx_fifos() #
void Clears txfifo allocation
Parameters
struct dwc3 *dwc: pointer to the DWC3 context
Description
Iterates through all the endpoint registers and clears the previous txfifo allocations.
__dwc3_gadget_ep_enable() #
int initializes a hw endpoint
Parameters
struct dwc3_ep *dep: endpoint to be initializedunsigned int action: one of INIT, MODIFY or RESTORE
Description
Caller should take care of locking. Execute all necessary commands to initialize a HW endpoint so it can be used by a gadget driver.
__dwc3_gadget_ep_disable() #
int disables a hw endpoint
Parameters
struct dwc3_ep *dep: the endpoint to disable
Description
This function undoes what __dwc3_gadget_ep_enable did and also removes requests which are currently being processed by the hardware and those which are not yet scheduled.
Caller should take care of locking.
dwc3_ep_prev_trb() #
struct dwc3_trb * returns the previous TRB in the ring
Parameters
struct dwc3_ep *dep: The endpoint with the TRB ringu8 index: The index of the current TRB in the ring
Description
Returns the TRB prior to the one pointed to by the index. If the index is 0, we will wrap backwards, skip the link TRB, and return the one just before that.
dwc3_prepare_one_trb() #
void setup one TRB from one request
Parameters
struct dwc3_ep *dep: endpoint for which this request is preparedstruct dwc3_request *req: dwc3_request pointerunsigned int trb_length: buffer size of the TRBunsigned int chain: should this TRB be chained to the next?unsigned int node: only for isochronous endpoints. First TRB needs different type.bool use_bounce_buffer: set to use bounce bufferbool must_interrupt: set to interrupt on TRB completion
dwc3_prepare_last_sg() #
int prepare TRBs for the last SG entry
Parameters
struct dwc3_ep *dep: The endpoint that the request belongs tostruct dwc3_request *req: The request to prepareunsigned int entry_length: The last SG entry sizeunsigned int node: Indicates whether this is not the first entry (for isoc only)
Description
Return the number of TRBs prepared.
__dwc3_stop_active_transfer() #
int stop the current active transfer
Parameters
struct dwc3_ep *dep: isoc endpointbool force: set forcerm bit in the commandbool interrupt: command complete interrupt after End Transfer command
Description
When setting force, the ForceRM bit will be set. In that case the controller won't update the TRB progress on command completion. It also won't clear the HWO bit in the TRB. The command will also not complete immediately in that case.
dwc3_gadget_start_isoc_quirk() #
int workaround invalid frame number
Parameters
struct dwc3_ep *dep: isoc endpoint
Description
This function tests for the correct combination of BIT[15:14] from the 16-bit microframe number reported by the XferNotReady event for the future frame number to start the isoc transfer.
In DWC_usb31 version 1.70a-ea06 and prior, for highspeed and fullspeed isochronous IN, BIT[15:14] of the 16-bit microframe number reported by the XferNotReady event are invalid. The driver uses this number to schedule the isochronous transfer and passes it to the START TRANSFER command. Because this number is invalid, the command may fail. If BIT[15:14] matches the internal 16-bit microframe, the START TRANSFER command will pass and the transfer will start at the scheduled time, if it is off by 1, the command will still pass, but the transfer will start 2 seconds in the future. For all other conditions, the START TRANSFER command will fail with bus-expiry.
In order to workaround this issue, we can test for the correct combination of BIT[15:14] by sending START TRANSFER commands with different values of BIT[15:14]: 'b00, 'b01, 'b10, and 'b11. Each combination is 2^14 uframe apart (or 2 seconds). 4 seconds into the future will result in a bus-expiry status. As the result, within the 4 possible combinations for BIT[15:14], there will be 2 successful and 2 failure START COMMAND status. One of the 2 successful command status will result in a 2-second delay start. The smaller BIT[15:14] value is the correct combination.
Since there are only 4 outcomes and the results are ordered, we can simply test 2 START TRANSFER commands with BIT[15:14] combinations 'b00 and 'b01 to deduce the smaller successful combination.
Let test0 = test status for combination 'b00 and test1 = test status for 'b01 of BIT[15:14]. The correct combination is as follow:
if test0 fails and test1 passes, BIT[15:14] is 'b01 if test0 fails and test1 fails, BIT[15:14] is 'b10 if test0 passes and test1 fails, BIT[15:14] is 'b11 if test0 passes and test1 passes, BIT[15:14] is 'b00
Synopsys STAR 9001202023: Wrong microframe number for isochronous IN endpoints.
dwc3_gadget_setup_nump() #
void calculate and initialize NUMP field of DWC3_DCFG
Parameters
struct dwc3 *dwc: pointer to our context structure
Description
The following looks like complex but it's actually very simple. In order to calculate the number of packets we can burst at once on OUT transfers, we're gonna use RxFIFO size.
To calculate RxFIFO size we need two numbers: MDWIDTH = size, in bits, of the internal memory bus RAM2_DEPTH = depth, in MDWIDTH, of internal RAM2 (where RxFIFO sits)
Given these two numbers, the formula is simple:
RxFIFO Size = (RAM2_DEPTH * MDWIDTH / 8) - 24 - 16;
24 bytes is for 3x SETUP packets 16 bytes is a clock domain crossing tolerance
Given RxFIFO Size, NUMP = RxFIFOSize / 1024;
dwc3_gadget_check_config() #
int ensure dwc3 can support the USB configuration
Parameters
struct usb_gadget *g: pointer to the USB gadget
Description
Used to record the maximum number of endpoints being used in a USB composite device. (across all configurations) This is to be used in the calculation of the TXFIFO sizes when resizing internal memory for individual endpoints. It will help ensured that the resizing logic reserves enough space for at least one max packet.
dwc3_get_dr_mode() #
int Validates and sets dr_mode
Parameters
struct dwc3 *dwc: pointer to our context structure
dwc3_core_soft_reset() #
int Issues core soft reset and PHY reset
Parameters
struct dwc3 *dwc: pointer to our context structure
dwc3_ref_clk_period() #
void Reference clock period configuration Default reference clock period depends on hardware configuration. For systems with reference clock that differs from the default, this will set clock period in DWC3_GUCTL register.
Parameters
struct dwc3 *dwc: Pointer to our controller context structure
dwc3_free_one_event_buffer() #
void Frees one event buffer
Parameters
struct dwc3 *dwc: Pointer to our controller context structurestruct dwc3_event_buffer *evt: Pointer to event buffer to be freed
dwc3_alloc_one_event_buffer() #
struct dwc3_event_buffer * Allocates one event buffer structure
Parameters
struct dwc3 *dwc: Pointer to our controller context structureunsigned int length: size of the event buffer
Description
Returns a pointer to the allocated event buffer structure on success otherwise ERR_PTR(errno).
dwc3_free_event_buffers() #
void frees all allocated event buffers
Parameters
struct dwc3 *dwc: Pointer to our controller context structure
dwc3_alloc_event_buffers() #
int Allocates num event buffers of size length
Parameters
struct dwc3 *dwc: pointer to our controller context structureunsigned int length: size of event buffer
Description
Returns 0 on success otherwise negative errno. In the error case, dwc may contain some buffers allocated but not all which were requested.
dwc3_event_buffers_setup() #
int setup our allocated event buffers
Parameters
struct dwc3 *dwc: pointer to our controller context structure
Description
Returns 0 on success otherwise negative errno.
dwc3_phy_setup() #
int Configure USB PHY Interface of DWC3 Core
Parameters
struct dwc3 *dwc: Pointer to our controller context structure
Description
Returns 0 on success. The USB PHY interfaces are configured but not initialized. The PHY interfaces and the PHYs get initialized together with the core in dwc3_core_init.
[1] Transfer Request Block
[2] Transfer Request Block pointing to another Transfer Request Block.
[3] The Debug File System
[4] The Config File System
[5] Command Block Wrapper