drivers/usb/cdns3/cdnsp-gadget.c
Source file repositories/reference/linux-study-clean/drivers/usb/cdns3/cdnsp-gadget.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/cdns3/cdnsp-gadget.c- Extension
.c- Size
- 52758 bytes
- Lines
- 2078
- 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.
- 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/moduleparam.hlinux/dma-mapping.hlinux/module.hlinux/iopoll.hlinux/delay.hlinux/log2.hlinux/slab.hlinux/string_choices.hlinux/pci.hlinux/irq.hlinux/dmi.hcore.hgadget-export.hdrd.hcdnsp-gadget.hcdnsp-trace.h
Detected Declarations
function Copyrightfunction Onlyfunction cdnsp_find_next_ext_capfunction cdnsp_set_link_statefunction cdnsp_disable_portfunction cdnsp_clear_port_change_bitfunction cdnsp_set_apb_timeout_valuefunction cdnsp_set_chicken_bits_2function cdnsp_clear_chicken_bits_2function cdnsp_quiescefunction cdnsp_haltfunction cdnsp_diedfunction cdnsp_startfunction cdnsp_resetfunction cdnsp_get_endpoint_indexfunction endpointfunction cdnsp_ep_enqueuefunction cdnsp_ep_dequeuefunction cdnsp_zero_in_ctxfunction cdnsp_configure_endpointfunction cdnsp_invalidate_ep_eventsfunction cdnsp_wait_for_cmd_complfunction cdnsp_halt_endpointfunction cdnsp_update_eps_configurationfunction cdnsp_setup_devicefunction cdnsp_setup_streams_ep_input_ctxfunction cdnsp_alloc_streamsfunction cdnsp_disable_slotfunction cdnsp_enable_slotfunction cdnsp_setup_devicefunction cdnsp_set_usb2_hardware_lpmfunction cdnsp_get_framefunction cdnsp_gadget_ep_enablefunction cdnsp_gadget_ep_disablefunction cdnsp_gadget_ep_free_requestfunction cdnsp_gadget_ep_queuefunction cdnsp_gadget_ep_dequeuefunction cdnsp_gadget_ep_set_haltfunction cdnsp_gadget_ep_set_wedgefunction cdnsp_gadget_givebackfunction cdnsp_runfunction cdnsp_gadget_udc_startfunction cdnsp_update_erst_dequeuefunction cdnsp_clear_cmd_ringfunction cdnsp_consume_all_eventsfunction cdnsp_stopfunction cdnsp_gadget_udc_stopfunction cdnsp_gadget_get_frame
Annotated Snippet
TRB_TO_EP_ID(data) == (pep->idx + 1)) {
data |= TRB_EVENT_INVALIDATE;
event->trans_event.flags = cpu_to_le32(data);
}
if (cdnsp_last_trb_on_seg(segment, event)) {
cycle_state ^= 1;
segment = pdev->event_ring->deq_seg->next;
event = segment->trbs;
} else {
event++;
}
}
}
int cdnsp_wait_for_cmd_compl(struct cdnsp_device *pdev)
{
struct cdnsp_segment *event_deq_seg;
union cdnsp_trb *cmd_trb;
dma_addr_t cmd_deq_dma;
union cdnsp_trb *event;
u32 cycle_state;
u32 retry = 10;
int ret, val;
u64 cmd_dma;
u32 flags;
cmd_trb = pdev->cmd.command_trb;
pdev->cmd.status = 0;
trace_cdnsp_cmd_wait_for_compl(pdev->cmd_ring, &cmd_trb->generic);
ret = readl_poll_timeout_atomic(&pdev->op_regs->cmd_ring, val,
!CMD_RING_BUSY(val), 1,
CDNSP_CMD_TIMEOUT);
if (ret) {
dev_err(pdev->dev, "ERR: Timeout while waiting for command\n");
trace_cdnsp_cmd_timeout(pdev->cmd_ring, &cmd_trb->generic);
pdev->cdnsp_state = CDNSP_STATE_DYING;
return -ETIMEDOUT;
}
event = pdev->event_ring->dequeue;
event_deq_seg = pdev->event_ring->deq_seg;
cycle_state = pdev->event_ring->cycle_state;
cmd_deq_dma = cdnsp_trb_virt_to_dma(pdev->cmd_ring->deq_seg, cmd_trb);
if (!cmd_deq_dma)
return -EINVAL;
while (1) {
flags = le32_to_cpu(event->event_cmd.flags);
/* Check the owner of the TRB. */
if ((flags & TRB_CYCLE) != cycle_state) {
/*
* Give some extra time to get chance controller
* to finish command before returning error code.
* Checking CMD_RING_BUSY is not sufficient because
* this bit is cleared to '0' when the Command
* Descriptor has been executed by controller
* and not when command completion event has
* be added to event ring.
*/
if (retry--) {
udelay(20);
continue;
}
return -EINVAL;
}
cmd_dma = le64_to_cpu(event->event_cmd.cmd_trb);
/*
* Check whether the completion event is for last queued
* command.
*/
if (TRB_FIELD_TO_TYPE(flags) != TRB_COMPLETION ||
cmd_dma != (u64)cmd_deq_dma) {
if (!cdnsp_last_trb_on_seg(event_deq_seg, event)) {
event++;
continue;
}
if (cdnsp_last_trb_on_ring(pdev->event_ring,
event_deq_seg, event))
cycle_state ^= 1;
event_deq_seg = event_deq_seg->next;
Annotation
- Immediate include surface: `linux/moduleparam.h`, `linux/dma-mapping.h`, `linux/module.h`, `linux/iopoll.h`, `linux/delay.h`, `linux/log2.h`, `linux/slab.h`, `linux/string_choices.h`.
- Detected declarations: `function Copyright`, `function Only`, `function cdnsp_find_next_ext_cap`, `function cdnsp_set_link_state`, `function cdnsp_disable_port`, `function cdnsp_clear_port_change_bit`, `function cdnsp_set_apb_timeout_value`, `function cdnsp_set_chicken_bits_2`, `function cdnsp_clear_chicken_bits_2`, `function cdnsp_quiesce`.
- 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.
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.