drivers/usb/dwc3/gadget.c
Source file repositories/reference/linux-study-clean/drivers/usb/dwc3/gadget.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/dwc3/gadget.c- Extension
.c- Size
- 130057 bytes
- Lines
- 4870
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/delay.hlinux/slab.hlinux/spinlock.hlinux/platform_device.hlinux/pm_runtime.hlinux/interrupt.hlinux/io.hlinux/list.hlinux/dma-mapping.hlinux/usb/ch9.hlinux/usb/gadget.hdebug.hcore.hgadget.hio.h
Detected Declarations
function Copyrightfunction successfunction dwc3_gadget_set_link_statefunction dwc3_ep0_reset_statefunction dwc3_ep_inc_trbfunction dwc3_ep_inc_enqfunction dwc3_ep_inc_deqfunction dwc3_gadget_del_and_unmap_requestfunction dwc3_gadget_givebackfunction dwc3_send_gadget_generic_commandfunction commandfunction DWC3_DEPCMD_CMDfunction dwc3_send_clear_stall_ep_cmdfunction dwc3_trb_dma_offsetfunction dwc3_alloc_trb_poolfunction dwc3_free_trb_poolfunction dwc3_gadget_set_xfer_resourcefunction dwc3_gadget_start_configfunction dwc3_gadget_set_ep_configfunction dwc3_gadget_calc_tx_fifo_sizefunction dwc3_gadget_calc_ram_depthfunction dwc3_gadget_clear_tx_fifosfunction dwc3_gadget_check_configfunction __dwc3_gadget_ep_enablefunction usb_endpoint_xfer_intfunction dwc3_remove_requestsfunction __dwc3_gadget_ep_disablefunction dwc3_gadget_ep0_enablefunction dwc3_gadget_ep0_disablefunction dwc3_gadget_ep_enablefunction dwc3_gadget_ep_disablefunction dwc3_gadget_ep_free_requestfunction dwc3_calc_trbs_leftfunction dwc3_prepare_one_trbfunction dwc3_needs_extra_trbfunction dwc3_prepare_last_sgfunction dwc3_prepare_trbs_sgfunction for_each_sgfunction list_for_each_entryfunction dwc3_prepare_trbs_linearfunction dwc3_prepare_trbsfunction list_for_each_entry_safefunction __dwc3_gadget_kick_transferfunction __dwc3_gadget_get_framefunction __dwc3_stop_active_transferfunction dwc3_gadget_start_isoc_quirkfunction __dwc3_gadget_start_isocfunction __dwc3_gadget_ep_queue
Annotated Snippet
while (--retries) {
reg = dwc3_readl(dwc, DWC3_DSTS);
if (reg & DWC3_DSTS_DCNRD)
udelay(5);
else
break;
}
if (retries <= 0)
return -ETIMEDOUT;
}
reg = dwc3_readl(dwc, DWC3_DCTL);
reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK;
/* set no action before sending new link state change */
dwc3_writel(dwc, DWC3_DCTL, reg);
/* set requested state */
reg |= DWC3_DCTL_ULSTCHNGREQ(state);
dwc3_writel(dwc, DWC3_DCTL, reg);
/*
* The following code is racy when called from dwc3_gadget_wakeup,
* and is not needed, at least on newer versions
*/
if (!DWC3_VER_IS_PRIOR(DWC3, 194A))
return 0;
/* wait for a change in DSTS */
retries = 10000;
while (--retries) {
reg = dwc3_readl(dwc, DWC3_DSTS);
if (DWC3_DSTS_USBLNKST(reg) == state)
return 0;
udelay(5);
}
return -ETIMEDOUT;
}
static void dwc3_ep0_reset_state(struct dwc3 *dwc)
{
unsigned int dir;
if (dwc->ep0state != EP0_SETUP_PHASE) {
dir = !!dwc->ep0_expect_in;
if (dwc->ep0state == EP0_DATA_PHASE)
dwc3_ep0_end_control_data(dwc, dwc->eps[dir]);
else
dwc3_ep0_end_control_data(dwc, dwc->eps[!dir]);
dwc->eps[0]->trb_enqueue = 0;
dwc->eps[1]->trb_enqueue = 0;
dwc3_ep0_stall_and_restart(dwc);
}
}
/**
* dwc3_ep_inc_trb - increment a trb index.
* @index: Pointer to the TRB index to increment.
*
* 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.
*/
static void dwc3_ep_inc_trb(u8 *index)
{
(*index)++;
if (*index == (DWC3_TRB_NUM - 1))
*index = 0;
}
/**
* dwc3_ep_inc_enq - increment endpoint's enqueue pointer
* @dep: The endpoint whose enqueue pointer we're incrementing
*/
static void dwc3_ep_inc_enq(struct dwc3_ep *dep)
{
dwc3_ep_inc_trb(&dep->trb_enqueue);
}
/**
* dwc3_ep_inc_deq - increment endpoint's dequeue pointer
* @dep: The endpoint whose enqueue pointer we're incrementing
*/
static void dwc3_ep_inc_deq(struct dwc3_ep *dep)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/delay.h`, `linux/slab.h`, `linux/spinlock.h`, `linux/platform_device.h`, `linux/pm_runtime.h`, `linux/interrupt.h`, `linux/io.h`.
- Detected declarations: `function Copyright`, `function success`, `function dwc3_gadget_set_link_state`, `function dwc3_ep0_reset_state`, `function dwc3_ep_inc_trb`, `function dwc3_ep_inc_enq`, `function dwc3_ep_inc_deq`, `function dwc3_gadget_del_and_unmap_request`, `function dwc3_gadget_giveback`, `function dwc3_send_gadget_generic_command`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.