How Data Is Transferred Between Linux USB Host and Device Using USB Endpoints
Communication between a Linux USB host system and a USB device follows a highly structured model defined by the USB specification. At the center of this model are USB endpoints - logical channels on the device through which data flows. Understanding how Linux uses these endpoints helps developers design drivers, debug issues, and optimize overall system performance.
1. What Are USB Endpoints?
A USB endpoint is a unidirectional data communication channel present inside the USB device. Each endpoint:
Endpoint 0 is always a control endpoint, mandatory for enumeration and standard commands.
2. Endpoint Types and Their Behavior
Linux controls these endpoints using URBs (USB Request Blocks) and the USB core driver.
3. USB Pipes: Host-Side View of Endpoints
Linux does not directly operate on endpoints — instead, it uses pipes, which are the host’s representation of device endpoints.
A USB pipe encapsulates:
There are 4 pipe types: control, bulk, interrupt, isochronous, corresponding to endpoint types.
How Pipes Are Created
During enumeration, Linux reads the device’s descriptors. It parses:
For each endpoint, Linux sets up a corresponding pipe (e.g., usb_rcvbulkpipe(), usb_sndbulkpipe() APIs) that the driver uses.
4. How Data Flows from Linux USB Host to a Device
Step 1: Driver Identifies the Endpoint
The driver parses endpoint descriptors found in:
struct usb_endpoint_descriptor *ep = &interface->endpoint[i].desc;
It checks:
Step 2: Driver Creates a Pipe
To send OUT data to the device’s bulk endpoint:
Recommended by LinkedIn
pipe = usb_sndbulkpipe(udev, ep->bEndpointAddress);
Step 3: Prepare an URB
URB is the data carrier between Host and USB Core.
struct urb *urb = usb_alloc_urb(0, GFP_KERNEL);
usb_fill_bulk_urb(urb, udev, pipe, buffer, length, callback, context);
Step 4: Submit URB
The host controller driver (EHCI/XHCI/OHCI/UHCI) handles the hardware transfer.
usb_submit_urb(urb, GFP_KERNEL);
Step 5: Device Receives Data via Endpoint Buffer
The USB device firmware reads the OUT endpoint FIFO or DMA buffer and processes the data.
5. How Data Flows from Device to Linux USB Host (IN Endpoint)
6. Role of Host Controller Driver (HCD)
Linux USB Core hands URBs to an HCD:
HCD is responsible for:
This ensures reliable, predictable data movement via endpoints.
7. Practical Example: USB to Serial Device
For a USB modem (CDC-ACM type):
Linux’s cdc_acm driver uses URBs to communicate through these endpoints.
8. Summary
USB endpoints are the fundamental channels controlling how data flows between a Linux USB host and a USB device. The host uses pipes, URBs, and USB Core APIs to interact with these endpoints. The type and configuration of each endpoint determine:
Understanding endpoint-based data transfer is essential for developing USB device drivers, debugging communication problems, and designing robust USB-based systems.
Follow newsletter Linux Core Concepts : Core Interface System
#LinuxKernel #EmbeddedLinux #USBDrivers #NetworkDeviceDriver #Networking #AI #AIDataCenter #DeviceDrivers #Networking #IoT #LinuxNetworking #CProgramming #KernelDevelopment #EmbeddedSystems #URB #LinuxInternals #OpenSource