Analysis of USB protocol architecture

MuggleZero 2021-11-25 18:05:13

One 、USB Some basic concepts of

  1. The Conduit (Pipe) It is the model of data transmission between host and device endpoint , There are two types of pipes : Unformatted
    Flow pipe (Stream Pipe) And a formatted information pipeline (Message Pipe). whatever USB Once the equipment is powered on, it exists
    An information pipeline , The default control pipeline ,USB The host obtains the device description through this pipeline 、 To configure 、 state , and
    Configure the device .

  2. Endpoint (Endpoint) yes USB The smallest unit in the equipment that can transmit and receive data , Support one-way or two-way data transmission
    transport . The number of endpoints supported by the device is limited , In addition to the default endpoint, low-speed devices support up to 2 Group endpoint (2 Inputs ,2
    Outputs ), High speed and full speed devices support up to 15 Group endpoint .

  3. Interface (Interface) Application software completes equipment control and data transmission through data exchange with equipment . Usually
    Multiple pipelines are required to complete data exchange , Because the same pipeline only supports one type of data transmission . Use it together to enter... Into the equipment
    Several pipelines controlled by rows are called interfaces of equipment .

  4. The relationship between devices and endpoints : One USB A device can include several endpoints , Different endpoints are distinguished by endpoint number and direction .
    Different endpoints can support different transmission types 、 Access interval and maximum packet size . Except endpoint 0 Outside , All endpoints only support
    Data transmission in one direction . Endpoint 0 Is a special endpoint , It supports two-way Of Control transmission . Pipe and endpoint associations , and
    The associated endpoints have the same properties , As supported Transfer type Maximum package length Transmission direction etc. .

  5. The descriptor (Descriptor) Describe the properties of the device (Attributes). It itself is a data structure , The first byte indicates
    The size of the descriptor ( Number of bytes ), The second byte indicates the type of descriptor (Type). The types of descriptors are :
    [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-8OH40HxS-1635519762323)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024907829.png)]

  1. Device descriptor (Device), General information describing a device .
    [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-5R2ZjWIj-1635519762324)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024907255.png)]
  2. Device decoration descriptor (Device_Qualifier), Information describing how a high-speed device should change at other speeds .
  3. Configuration descriptor (Configuration), Describe a specific device configuration , Such as the number of interfaces, etc . One USB The device has one or more configuration descriptors . Each configuration has one or more interfaces and each interface has 0 One or more endpoints .
    [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-JkB3AUZo-1635519762325)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024908442.png)]
  4. Other speed configuration descriptors (Other_speed_configuration), Describe the operation of high-speed equipment at other possible speeds
    A configuration .
  5. Interface descriptors (Interface), Describe a specific interface in a configuration .
  6. Endpoint descriptor (Endpoint), Describe the information required by the host to determine the bandwidth required by the endpoint . This descriptor can only be attached to GetDescriptor() or GetDescriptor() Sent in request , Cannot be transmitted separately . Endpoint 0 There is no such descriptor .
    [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-fewnmTJt-1635519762326)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024908675.png)]
    [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-hGob3BIf-1635519762327)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024908690.png)]
  7. String descriptor (String), The first 0 A string descriptor specifies the language supported by the device , Other descriptors contain
    One UNICODE character string . Device descriptor , Configuration descriptor and Interface descriptors may contain string descriptors .
  1. USB Device request (USB Device Request) The request is sent from the host to the device through the control pipeline .
    Standard device requests are :
  1. Clear Feature
  2. Get Configuration
  3. Get Descriptor
  4. Get Interface
  5. Get Status
  6. Set Address
  7. Set Configuration
  8. Set Descriptor
  9. Set Feature
  10. Set Interface
  11. Synch Frame

Two 、USB3.0 System topology

The system can only have 7 The tree structure of the layer
At most, it can only support 127 Two devices and Hub
Host+RootHub Always on the first floor
Reunite with (Compound) The equipment generally occupies two floors
Functional devices cannot be used as non leaf nodes , Only Hub Can only be

USB3.0 Hub It actually contains a USB2 Of Hub And a SuperSpeed Hub

3、 ... and 、 USB3.0 Important characteristics of :

  1. Adds an important data transfer rate
  2. Point to point transmission of packets , Minimize the number of active links
  3. Asynchronous notification function , Eliminates the need for polling
  4. Link level based power management , This is the basic design of bus structure
  5. Backward compatibility USB2.0, Both driver level and physical layer level achieve the purpose of compatibility

Four 、USB3.0 And USB2.0 The difference between

  1. Data transfer rate , 3.0 yes SuperSpeed 5.0Gbps,
    2.0 yes 1.5Mbps, 12Mbps or 480Mbps

  2. Data interface , 3.0 It's full duplex , Independent of USB 2.0 Four differential signals of the signal , Support simultaneous two-way data transmission
    2.0 It's half duplex , Dual differential signal , One way data transmission , The transmission direction of the general route needs to be negotiated in advance

  3. Number of signal lines , 3.0 yes 4 road SuperSpeed cable , 2 road HighSpeed Data lines and 2 Power supply and ground wire
    2.0 yes 2 road LS/FS/HS cable , 2 Power supply and ground wire

  4. Bus transaction protocol , 3.0 It is host led asynchronous transmission flow control , Packet transmission can be explicitly routed
    2.0 It is the transmission flow control of host dominated polling mode , Packet transmission is broadcast to all devices

  5. Power management , 3.0 It is multi-level link power management , Support Idle, sleep and suspend state
    2.0 It is managed at the port level , Can be in entry/exit There are two levels of hang up status on the

  6. Bus power supply , 3.0 Is and USB 2.0 almost , Only the unconfigured power supply has 50% Increase of , The configured power supplies are 80% Increase of

  7. Host controller ,3.0 It's using xHCI,2.0 It is EHCI.xHCI Virtualization technology support is provided in .

5、 ... and 、USB3.0 Power status

  1. U0, Link active
  2. U1, Link idle - fast exit. Exit delay us level
  3. U2, Link idle - slow exit. Exit delay us-ms level
  4. U3, Link suspend. No clock signal , Exit delay us-ms level

6、 ... and 、USB3.0 Packet type

  1. Link Management Packets, Link management package , Only between two connected ports , It is mainly used for link management
  2. Transaction Packets, Transaction package , Occurs between the device and the host , Used to control the flow of packets , Configure devices and Hubs. It has no data
  3. Data Packets, Data packets , Occurs between the device and the host . It consists of two parts : Baotou and actual data . The data part also includes a 32 Bit CRC Check code to ensure data integrity .
  4. Isochronous Timestamp Packets, Synchronization timestamp package , It is the only multicast way to send . The sending direction is from the host to all U0 Status device .

7、 ... and 、USB Transfer type

1. Control transmission (Control Transfers)
Control transmission is a reliable two-way transmission , Primary control transmission can be divided into three stages .

The first stage is from HOST To Device Of SETUP Transaction transfer , This stage specifies the request type for this control transmission ;
The second stage is the data stage , Some requests have no data phase ;
The third stage is the state stage , Through a IN/OUT The transmission indicates whether the request completed successfully .

The control is transmitted through the control pipeline in the application software and Device Between control endpoints , The data transmitted during control transmission is
With format definition ,USB The device or host can parse the meaning of the obtained data according to the format definition . None of the other three transport types has a format definition .

The control transmission has a fixed requirement for the maximum packet length . For high-speed equipment, the value is 64Byte; For low-speed equipment, the value is 8; Full speed equipment
It can be 8 or 16 or 32 or 64.
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-ggQAbtj4-1635519762327)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024907614.png)]
2. Bulk transfer (Bulk Transfers)
Batch transmission is a reliable one-way transmission , But the delay is not guaranteed , It makes full use of the available bandwidth to complete the transmission , It is suitable for transmission with large amount of data .

low speed USB The device does not support batch transfer , The maximum packet length of the high-speed batch endpoint is 512, The maximum packet length of the full speed batch endpoint can be 8、16、32、64.

Batch transfer is accessing USB Bus time , Has the lowest priority over other transport types ,USB HOST Always prioritize other types of transfers ,
When the bus bandwidth is surplus, batch transmission is arranged . High speed batch endpoints must support PING operation , Report the status of the endpoint to the host ,NYET
Indicates a negative response , Not ready to receive the next packet ,ACK Indicates a positive response , Ready to receive the next packet .
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-FsxxXdY6-1635519762328)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024907113.png)]
3. Interrupt transmission (Interrupt Transfers)
Interrupt transmission is a polling transmission mode , It's a one-way transmission ,HOST Query the interrupt endpoint at fixed intervals , If you have any
Data transmission or can receive data, return data or send data , Otherwise return to NAK, Indicates that you are not ready . The delay of interrupt transmission is guaranteed
Prove , But not real-time transmission , It is a reliable transmission with limited delay , Support error retransmission .

For high speed / Full speed / Low speed endpoint , The maximum packet length can reach 1024/64/8 Bytes. High speed interrupt transmission shall not occupy more than 80% Of
Microframe time , Full speed and low speed shall not exceed 90%. The polling interval of the interrupt endpoint is defined in the endpoint descriptor , The polling interval of the full speed endpoint can be
So 1255mS, The low speed endpoint is 10255mS, The high-speed endpoint is (2interval-1)*125uS, among interval take 1 To 16 Between the value of the .

In addition to high-speed and high bandwidth interrupt endpoints , Only one interruption of transaction transmission is allowed in a microframe , High speed and high bandwidth endpoints can enter at most one microframe
The line interrupts the transaction transmission three times , Transmission up to 3072 Bytes of data .
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-XF4mr8rr-1635519762329)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024907854.png)]
4. Synchronous transmission (Isochronous Transfers)
Synchronous transmission is a kind of real-time transmission 、 Unreliable transmission , Error retransmission mechanism is not supported . Only high-speed and full speed endpoints support synchronous transmission , High speed synchronous terminal
The maximum packet length of a point is 1024, Low speed is 1023.

In addition to high-speed and high bandwidth synchronization endpoints , Only one synchronous transaction transmission is allowed in a microframe , High speed and high bandwidth endpoints can perform up to three operations in one microframe
Subsynchronous transaction transfer , Transmission up to 3072 Bytes of data . Full speed synchronous transmission shall not occupy more than 80% Frame time of , High speed synchronous transmission shall not occupy
exceed 90% Microframe time .

The access of synchronous endpoint is the same as that of interrupt endpoint , There is a fixed time interval limit .

On the host controller and USB HUB There is another transmission between —— Separate transmission (Split Transaction), It works only on the host controller and HUB In between , Through separate transmission , Allow full speed / Connect the low-speed device to the high-speed host . Separate transmission for USB Transparent to the device 、 Invisible .

8、 ... and 、 OTG agreement

OTG Equipment adoption Mini-AB Socket , Compared with the traditional USB cable ,Mini-AB The interface has one more data line ID,ID Whether the cable is connected will Mini-AB The interface is divided into Mini-A and Mini-B There are two types of interfaces . stay OTG In the process of data connection between devices , adopt OTG cable Mini-A and Mini-B Interface to determine OTG The master and slave of the device : Access Mini-A The interface device defaults to A equipment ( Host device ); Access Mini-B Interface devices , The default is B equipment ( Slave device ).

A Equipment and B The equipment does not need to exchange cable interfaces , Through the host exchange protocol (HNP) Realization A、B Role exchange between devices . meanwhile , To save power ,OTG Allow bus idle A The equipment judges the power supply . here , if B The device wants to use the bus , You can use the session request protocol (SRP) request A The device supplies power .
8.1 HNP( Host exchange ) agreement

When Mini-A Interface access A Equipment and determine A When the device is a host ; if B The device wants to be the host , be A Equipment to B Device send SetFeature command , allow B The device performs host exchange .B The device detected a bus hang 5ms after , Hang up D+ And start the HNP, Put the bus in SE0 state . here A The device has detected that the bus is in SE0 state , The idea that B The device initiates a host exchange ,A The device responds . stay B Device discovery D+ The line is high and D- The line is low level (J state ), Express A The device identifies B The equipment HNP request .B The device starts bus reset and has bus control , Host exchange protocol complete .

8.2 SRP( Conversation request ) agreement

For hosts , Request to be able to respond to session requests ; For equipment , Only the ability to initiate SRP agreement .OTG equipment , Not only is it required to initiate SRP, And it's responsive SRP request .
SRP It is divided into data line pulse modulation and voltage pulse modulation ,B Device launch SRP The following two conditions must be met :
1) B Device detected A The device is below its effective voltage threshold , meanwhile B The device is below a valid voltage threshold .
2) B The device must detect D+ and D- The data line is at least 2ms Is below the valid threshold for a period of time , It's in SE0 state .

Data line pulse modulation session request :B The equipment must wait until the above two conditions are met , Connect the data line to the pull-up resistor for a certain time , in preparation for A The device filters the instantaneous voltage on the data line . meanwhile ,B Equipment pull-up D+ To facilitate initialization in full speed mode .A The device is detecting D+ Go high or D- When it becomes low, it produces SRP Indicating signal .

Vbus Pulse modulation session request :B The device also needs to wait for the above two initialization conditions to be met , then B The device increases the bus voltage by charging the capacitor , To reach the voltage threshold on the bus , Wake up the A equipment . During the charging process , Be sure to ensure that the peak voltage of charging is within a certain range to avoid burning A equipment .
3. USB Driver Architecture

USB The driver architecture is shown in the figure below :

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-vz9ok0ed-1635519762329)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024911989.png)]
3.1 USB Host side driver
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-oTevXc87-1635519762330)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024912570.png)]
USB The core (USBD) As a whole USB The core part of the drive , It can be seen from the figure above , One side USBD To receive USB The data of the host controller is processed , And pass it to the upper device driver software ; It also receives non data from the upper layer USB Format data stream , Carry out corresponding data processing and then transfer it to USB The host controller drives .
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-jBSMRmBs-1635519762330)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024912800.png)]
USB Data transmission is in the form of URB(USB Request Block) request 、URB Generate 、URB submit 、URB Release as main line . It can be seen from the figure above , After loading the controller drive , Register hub ,hub and hcd Drive as a whole . next , The host obtains the control descriptor and other information of the device through control transmission , Then, the whole process of control transmission is described in detail .usb_submit_urb The call depends on whether it is connected to the root hub urb_enqueue or rh_urb_enqueue function .
USB The slave device is connected to... Through a hub or root hub USB On a host . such as : The host interacts with the outside world through the root hub , The root hub notifies... By detecting changes in the state of the data line USB Does the host have USB Peripheral access .
In the process of host controller drive loading , Registered root hub , Then match the corresponding hub The driver , At the same time Hub Setting of polling function and status processing function . such , once hub Hub status changes , There will be a corresponding interrupt , The host controller will execute the corresponding interrupt processing function , The following figure for hub Flow chart of driver .
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-1hAPoJRy-1635519762331)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024920893.png)]

 USB Core Medium usb_init() Function to complete the right hub Threads (khubd, stay usb_hub_init Function to actually create ) The creation of , Then complete the detection of corresponding equipment . When the host controller drives to detect , take hub The driver is combined with the host controller driver , Complete calls to each other . In contrast to mass storage, the device and the host are controlled by / Bulk transfer , Between the hub and the host through an interrupt / Control mode to complete data interaction .

  • 1.

3.2 USB Device side drive
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-tValuejY-1635519762331)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024920442.png)]

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-8GHZvppK-1635519762332)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024920220.png)]

 It can be seen from the figure above , The device driver consists of two parts :
1) The underlying device controller drives
2) Upper mass storage class driver

  • 1.
  • 2.
  • 3.

3.2.1 Device controller drives

USB The main implementation of device controller driver Gadget API Defined functions and interrupt service functions , It can be divided into :API Function implementation module and interrupt processing module .
API The function mainly implements Gadget API Defined functions , Like a structure usb_ep_ops and usb_gadget_ops The function in 、usb_gadget_register_driver function . These functions are for Gadget Driver call .
The interrupt processing module mainly processes various interrupts generated by the device controller , Including endpoint interrupts 、 Reset 、 Suspend, etc .

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-rUKKHYMx-1635519762332)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024926681.png)]

The figure above shows the basic architecture of the device side controller , It's basically done Gadget Driver and controller driver binding 、usb_gadget_register_driver register .
3.3 OTG drive
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-rAg7mVBY-1635519762333)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024926525.png)]

OS_FS: file system
USBD: USB The core
HCD: The host controller drives
UDC: Device end controller driver

OTG Device support HNP and SRP agreement .OTG Equipment passing USB OTG Connect the cables together , Middle connection Mini-A The equipment of the interface is A equipment , The default is host side ,Mini-B The interface device defaults to B equipment . When A、B After the device completes data interaction ,A、B Between devices USB OTG The cable enters the suspended state , As shown in the figure below :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-0Xl86Ca4-1635519762333)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024926215.png)]

When B Device write b_bus_req, towards A Device launch HNP request . stay A After the device responds ,A Device send a_set_b_hnp_en,B After the device responds, it enters the host state , Send requests at the same time, using A equipment set_device, such A、B The device completes the master-slave exchange .
4. USB Transmission flow
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-hLftzgwD-1635519762334)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024926952.png)]
4.1 USB Initialization process

USB Drive as a system , It integrates many driver modules , The registration process is very complex . from USB From a system perspective ,USB The host driver mainly includes :

  1. USB Nuclear drive

  2. The host controller drives

  3. Hub drive

The loading execution process of the driver is shown in the figure below :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-XjKaqkvM-1635519762334)(http://2.eewimg.cn/news/uploadfile/2015/0821/20150821024930539.png)]
USB Initialization process
4.1.1 USB Core The initialization

USB Drive from USB Subsystem initialization begins ,USB The initialization of the subsystem is in the file driver/usb/core/usb.c
[cpp] view plaincopy

subsys_initcall(usb_init);
module_exit(usb_exit);
subsys_initcall() Is a macro , It can be understood as module_init(). Because this part of the code is very important , Developers see it as a subsystem , Not just a module .USB Core This module does not represent a device , It's all USB The module on which the device depends . stay Linux in , Device drivers in such a category are reduced to a subsystem .subsys_initcall(usb_init) Tell us ,usb_init Is the real initialization function , and usb_exit It will be the whole USB Cleanup function at the end of the subsystem .

  • 1.
  • 2.
  • 3.
  • 4.

4.1.2 Initialization of host controller and drive execution ( With EHCI For example )

 module_init(otg_init); Module registration
static init __init otg_init(void);
platform_driver_register(); Platform registration
static int __init otg_probe(struct platform_device *pdev); Probe handler
reg = platform_get_resource(pdev, IORESOURCE_MEM, 0); Get register information
data = platform_get_resource(pdev,IORESOURCE_MEM, 1); Get memory information
irq = platform_get_irq(pdev,0); Get interrupt number
usb_create_hcd(&otg_hc_driver, &pdev->dev, pdev->dev.bus_id);

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

Allocation and initialization HCD Structure . Allocate device data space , Initialize counter 、 Bus 、 Timer 、hcd The value of each member of the structure .

ret = usb_add_hcd(hcd,irq,SA_INTERRUPT);

  • 1.

complete HCD Initialization and registration of structures . apply buffer, Register bus 、 Allocate device side memory space , Apply for an interrupt from the interrupt vector table , Register the root hub , Poll the root hub status .
4.1.3 Register hub

 register_root_hub(hcd);

  • 1.

stay USB During system driven loading , The thread that created the hub (khubd), And always query the corresponding thread transactions .HCD Driving medium , Add the hub as a device to the host controller driver , Then initialize the hub port . stay USB The host looks , The root hub itself is also USB The host device .USB After the host driver is loaded , Start registering the root hub , And loaded into the host driver as a device .
USB The host and USB Data interaction between devices ,USB The device itself has no bus control ,U The disk passively receives USB The host sends the information and responds .USB The host controller and the root hub constitute the host system , Then connect other USB equipment .
In order to better detect the state change of the root hub ,USB The host controller driver adds a status polling function , Poll the root hub for changes in state at regular intervals . Once the root hub state changes , The host controller will respond accordingly .
USB The host and USB Data transmission between devices in order to URB(USB Request Block) In the form of .
4.2 URB Transmission process

USB During initialization , Whether it's a host controller driver or a root hub driver , It's all through URB Transmit and obtain device information .

4.2.1 apply URB

struct urb *usb_alloc_urb(int iso_packets, gfp_t mem_flags)
by urb Allocate memory and perform initialization .

  • 1.
  • 2.

4.2.2 initialization URB
Initialize specific urb package

static inline void usb_fill_bulk_urb(struct urb *urb,
struct usb_device *dev,
unsigned int pipe,
void *transfer_buffer,
int buffer_length,
usb_complete_t complete_fn,
void *context)
static inline void usb_fill_control_urb(struct urb *urb,
struct usb_device *dev,
unsigned int pipe,
unsigned char *setup_packet,
void *transfer_buffer,
int buffer_length,
usb_complete_t complete_fn,
void *context)
static inline void usb_fill_int_urb(struct urb *urb,
struct usb_device *dev,
unsigned int pipe,
void *transfer_buffer,
int buffer_length,
usb_complete_t complete_fn,
void *context,
int interval)

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.

Under different transmission modes , Drive to apply for different URB. among ,Linux The kernel only supports three kinds of transmission events other than synchronous transmission ,ISO The transaction needs to be initialized manually . Control transport transactions 、 Batch transfer transactions 、 Interrupt transfer transaction API As shown above .
Three transaction transfer modes URB Initialization functions have many similarities , The main parameters are as follows :
• urb: In transaction transfer urb
• dev: The destination device of the transaction transfer
• pipe: USB Host and USB A channel for data transmission between devices
• transfer_buffer: The first address of the memory buffer requested to send data
• length: The length of the transmit data buffer
• context: complete The context of the function
• complete_fn: Call completion function
• usb_fill_control_urb() Of setup_packet: Device packet to be sent
• usb_fill_int_urb() Of interval: Two in interrupt transmission URB Scheduling interval

4.2.3 Submit URB

URB After initialization ,USBD Begin to pass usb_start_wait_urb() Submit urb request ( It calls usb_submit_urb To really send URB request ), add to completition function . Next , from message.c To the host controller (hcd.c), Start really usb_hcd_submit_urb(). here , Depending on whether it is a root hub , Enter different work queues .

 usb_start_wait_urb->
usb_submit_urb->
usb_hcd_submit_urb

  • 1.
  • 2.
  • 3.

a) root_hub transmission

if root hub, Will call rh_urb_enqueue(), There are two types of transport transactions ( Control transmission and interrupt transmission

static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb)
{
if (usb_endpoint_xfer_int(&urb->ep->desc)) // Interrupt transmission
return rh_queue_status (hcd, urb);
if (usb_endpoint_xfer_control(&urb->ep->desc)) // Control transmission
return rh_call_control (hcd, urb);
return -EINVAL;
}

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

b) Not root_hub transmission
For very root_hub transmission , It calls :

 status = hcd->driver->urb_enqueue(hcd, urb, mem_flags);

  • 1.

c) Bulk transfer
root_hub There is no batch transfer process , Follow the control transmission process , Control transmission is ultimately through switch The statement jumps to Bulk-Only In the transmission process .

Please bring the original link to reprint ,thank
Similar articles

2021-11-25

2021-11-25

2021-11-25

2021-11-25