drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
Source file repositories/reference/linux-study-clean/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/gadget/udc/cdns2/cdns2-gadget.c- Extension
.c- Size
- 61489 bytes
- Lines
- 2469
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/dma-mapping.hlinux/pm_runtime.hlinux/interrupt.hlinux/property.hlinux/string_choices.hlinux/dmapool.hlinux/iopoll.hcdns2-gadget.hcdns2-trace.h
Detected Declarations
function Copyrightfunction clear_reg_bit_32function clear_reg_bit_8function set_reg_bit_8function cdns2_get_dma_posfunction cdns2_select_epfunction cdns2_trb_virt_to_dmafunction cdns2_free_tr_segmentfunction cdns2_alloc_tr_segmentfunction cdns2_ep_stall_flushfunction cdns2_ep_inc_trbfunction cdns2_ep_inc_enqfunction cdns2_ep_inc_deqfunction cdns2_enable_l1function cdns2_get_speedfunction cdns2_gadget_givebackfunction cdns2_wa1_restore_cycle_bitfunction cdns2_wa1_update_guardfunction cdns2_wa1_tray_restore_cycle_bitfunction cdns2_prepare_ringfunction cdns2_dbg_request_trbsfunction cdns2_count_trbsfunction cdns2_count_sg_trbsfunction for_each_sgfunction transactionfunction cdns2_ep_tx_isocfunction cdns2_ep_tx_bulkfunction cdns2_set_drdyfunction cdns2_prepare_first_isoc_transferfunction cdns2_ep_run_transferfunction cdns2_start_all_requestfunction cdns2_trb_handledfunction cdns2_skip_isoc_tdfunction cdns2_transfer_completedfunction cdns2_wakeupfunction cdns2_rearm_transferfunction cdns2_handle_epx_interruptfunction cdns2_disconnect_gadgetfunction cdns2_usb_irq_handlerfunction cdns2_thread_usb_irq_handlerfunction cdns2_thread_irq_handlerfunction for_each_set_bitfunction cdns2_eps_onchip_buffer_initfunction cdns2_ep_configfunction cdns2_gadget_ep_free_requestfunction cdns2_gadget_ep_enablefunction cdns2_gadget_ep_disablefunction cdns2_ep_enqueue
Annotated Snippet
if (doorbell) {
pep->wa1_cycle_bit = pep->ring.pcs ? TRB_CYCLE : 0;
pep->wa1_set = 1;
pep->wa1_trb = trb;
pep->wa1_trb_index = pep->ring.enqueue;
trace_cdns2_wa1(pep, "set guard");
return 0;
}
}
return 1;
}
static void cdns2_wa1_tray_restore_cycle_bit(struct cdns2_device *pdev,
struct cdns2_endpoint *pep)
{
int dma_index;
u32 doorbell;
doorbell = !!(readl(&pdev->adma_regs->ep_cmd) & DMA_EP_CMD_DRDY);
dma_index = cdns2_get_dma_pos(pdev, pep);
if (!doorbell || dma_index != pep->wa1_trb_index)
cdns2_wa1_restore_cycle_bit(pep);
}
static int cdns2_prepare_ring(struct cdns2_device *pdev,
struct cdns2_endpoint *pep,
int num_trbs)
{
struct cdns2_trb *link_trb = NULL;
int doorbell, dma_index;
struct cdns2_ring *ring;
u32 ch_bit = 0;
ring = &pep->ring;
if (num_trbs > ring->free_trbs) {
pep->ep_state |= EP_RING_FULL;
trace_cdns2_no_room_on_ring("Ring full\n");
return -ENOBUFS;
}
if ((ring->enqueue + num_trbs) >= (TRBS_PER_SEGMENT - 1)) {
doorbell = !!(readl(&pdev->adma_regs->ep_cmd) & DMA_EP_CMD_DRDY);
dma_index = cdns2_get_dma_pos(pdev, pep);
/* Driver can't update LINK TRB if it is current processed. */
if (doorbell && dma_index == TRBS_PER_SEGMENT - 1) {
pep->ep_state |= EP_DEFERRED_DRDY;
return -ENOBUFS;
}
/* Update C bt in Link TRB before starting DMA. */
link_trb = ring->trbs + (TRBS_PER_SEGMENT - 1);
/*
* For TRs size equal 2 enabling TRB_CHAIN for epXin causes
* that DMA stuck at the LINK TRB.
* On the other hand, removing TRB_CHAIN for longer TRs for
* epXout cause that DMA stuck after handling LINK TRB.
* To eliminate this strange behavioral driver set TRB_CHAIN
* bit only for TR size > 2.
*/
if (pep->type == USB_ENDPOINT_XFER_ISOC || TRBS_PER_SEGMENT > 2)
ch_bit = TRB_CHAIN;
link_trb->control = cpu_to_le32(((ring->pcs) ? TRB_CYCLE : 0) |
TRB_TYPE(TRB_LINK) | TRB_TOGGLE | ch_bit);
}
return 0;
}
static void cdns2_dbg_request_trbs(struct cdns2_endpoint *pep,
struct cdns2_request *preq)
{
struct cdns2_trb *link_trb = pep->ring.trbs + (TRBS_PER_SEGMENT - 1);
struct cdns2_trb *trb = preq->trb;
int num_trbs = preq->num_of_trb;
int i = 0;
while (i < num_trbs) {
trace_cdns2_queue_trb(pep, trb + i);
if (trb + i == link_trb) {
trb = pep->ring.trbs;
num_trbs = num_trbs - i;
i = 0;
} else {
i++;
}
Annotation
- Immediate include surface: `linux/dma-mapping.h`, `linux/pm_runtime.h`, `linux/interrupt.h`, `linux/property.h`, `linux/string_choices.h`, `linux/dmapool.h`, `linux/iopoll.h`, `cdns2-gadget.h`.
- Detected declarations: `function Copyright`, `function clear_reg_bit_32`, `function clear_reg_bit_8`, `function set_reg_bit_8`, `function cdns2_get_dma_pos`, `function cdns2_select_ep`, `function cdns2_trb_virt_to_dma`, `function cdns2_free_tr_segment`, `function cdns2_alloc_tr_segment`, `function cdns2_ep_stall_flush`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source 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.