sound/usb/endpoint.c
Source file repositories/reference/linux-study-clean/sound/usb/endpoint.c
File Facts
- System
- Linux kernel
- Corpus path
sound/usb/endpoint.c- Extension
.c- Size
- 50439 bytes
- Lines
- 1909
- Domain
- Driver Families
- Bucket
- sound/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.
- 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/gfp.hlinux/init.hlinux/ratelimit.hlinux/usb.hlinux/usb/audio.hlinux/slab.hsound/core.hsound/pcm.hsound/pcm_params.husbaudio.hhelper.hcard.hendpoint.hpcm.hclock.hquirks.h
Detected Declarations
struct snd_usb_iface_refstruct snd_usb_clock_reffunction snd_usb_endpoint_set_paramsfunction formatfunction release_urb_ctxfunction ep_state_runningfunction ep_state_updatefunction snd_usb_endpoint_implicit_feedback_sinkfunction synced_next_packet_sizefunction next_packet_sizefunction snd_usb_endpoint_next_packet_sizefunction call_retire_callbackfunction retire_outbound_urbfunction retire_inbound_urbfunction has_tx_length_quirkfunction prepare_silent_urbfunction prepare_outbound_urbfunction prepare_inbound_urbfunction notify_xrunfunction next_packet_fifo_enqueuefunction next_packet_fifo_dequeuefunction push_back_to_ready_listfunction snd_usb_queue_pending_output_urbsfunction scoped_guardfunction snd_complete_urbfunction snd_usb_endpoint_free_allfunction clock_ref_findfunction snd_usb_get_endpointfunction list_for_each_entryfunction snd_usb_endpoint_free_allfunction endpoint_set_syncintervalfunction endpoint_compatiblefunction snd_usb_endpoint_compatiblefunction snd_usb_endpoint_closefunction snd_usb_endpoint_set_syncfunction snd_usb_endpoint_set_callbackfunction endpoint_set_interfacefunction snd_usb_endpoint_openfunction snd_usb_endpoint_suspendfunction wait_clear_urbsfunction snd_usb_endpoint_sync_pending_stopfunction stop_urbsfunction scoped_guardfunction release_urbsfunction data_ep_set_paramsfunction sync_ep_set_paramsfunction update_clock_ref_ratefunction snd_usb_endpoint_set_params
Annotated Snippet
struct snd_usb_iface_ref {
unsigned char iface;
bool need_setup;
int opened;
int altset;
struct list_head list;
};
/* clock refcounting */
struct snd_usb_clock_ref {
unsigned char clock;
atomic_t locked;
int opened;
int rate;
bool need_setup;
struct list_head list;
};
/*
* snd_usb_endpoint is a model that abstracts everything related to an
* USB endpoint and its streaming.
*
* There are functions to activate and deactivate the streaming URBs and
* optional callbacks to let the pcm logic handle the actual content of the
* packets for playback and record. Thus, the bus streaming and the audio
* handlers are fully decoupled.
*
* There are two different types of endpoints in audio applications.
*
* SND_USB_ENDPOINT_TYPE_DATA handles full audio data payload for both
* inbound and outbound traffic.
*
* SND_USB_ENDPOINT_TYPE_SYNC endpoints are for inbound traffic only and
* expect the payload to carry Q10.14 / Q16.16 formatted sync information
* (3 or 4 bytes).
*
* Each endpoint has to be configured prior to being used by calling
* snd_usb_endpoint_set_params().
*
* The model incorporates a reference counting, so that multiple users
* can call snd_usb_endpoint_start() and snd_usb_endpoint_stop(), and
* only the first user will effectively start the URBs, and only the last
* one to stop it will tear the URBs down again.
*/
/*
* convert a sampling rate into our full speed format (fs/1000 in Q16.16)
* this will overflow at approx 524 kHz
*/
static inline unsigned get_usb_full_speed_rate(unsigned int rate)
{
return ((rate << 13) + 62) / 125;
}
/*
* convert a sampling rate into USB high speed format (fs/8000 in Q16.16)
* this will overflow at approx 4 MHz
*/
static inline unsigned get_usb_high_speed_rate(unsigned int rate)
{
return ((rate << 10) + 62) / 125;
}
/*
* release a urb data
*/
static void release_urb_ctx(struct snd_urb_ctx *u)
{
if (u->urb && u->buffer_size)
usb_free_coherent(u->ep->chip->dev, u->buffer_size,
u->urb->transfer_buffer,
u->urb->transfer_dma);
usb_free_urb(u->urb);
u->urb = NULL;
u->buffer_size = 0;
}
static const char *usb_error_string(int err)
{
switch (err) {
case -ENODEV:
return "no device";
case -ENOENT:
return "endpoint not enabled";
case -EPIPE:
return "endpoint stalled";
case -ENOSPC:
return "not enough bandwidth";
case -ESHUTDOWN:
return "device disabled";
Annotation
- Immediate include surface: `linux/gfp.h`, `linux/init.h`, `linux/ratelimit.h`, `linux/usb.h`, `linux/usb/audio.h`, `linux/slab.h`, `sound/core.h`, `sound/pcm.h`.
- Detected declarations: `struct snd_usb_iface_ref`, `struct snd_usb_clock_ref`, `function snd_usb_endpoint_set_params`, `function format`, `function release_urb_ctx`, `function ep_state_running`, `function ep_state_update`, `function snd_usb_endpoint_implicit_feedback_sink`, `function synced_next_packet_size`, `function next_packet_size`.
- Atlas domain: Driver Families / sound/usb.
- Implementation status: integration 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.