A USB host controller and its hierarchical prefetching method
By using a hierarchical prefetching method, the problem of prolonged response time in low-power USB 3.2 links is solved, resulting in faster first-packet response and higher transmission efficiency and reliability.
Patent Information
- Application Number
- CN202611612099.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-19
- Publication Date
- 2026-11-17
AI Technical Summary
When existing USB 3.2 links enter a low-power state without pending services, the response time is prolonged, and invalid memory access and data transfer may occur during the link recovery process, affecting transmission efficiency and reliability.
The system employs a prefetch transaction establishment module, a hierarchical prefetch control module, a restricted read module, a read verification module, and a consistency commit module. By determining the endpoint doorbell status and DDR status, hierarchical prefetch transactions execute TRB parsing and payload preparation in parallel, ensuring that only valid data is read during link recovery.
It shortens the first packet response time for short bursts of business, improves memory access efficiency and transmission reliability, and avoids invalid reads and resource waste.
Smart Images

Figure CN123115011A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of USB host controller technology, and more specifically to a USB host controller and its hierarchical prefetching method. Background Technology
[0002] When there is no pending service, a USB 3.2 link can transition from an active state to a low-power state. When an endpoint generates a new transmission task, the link exits the handshake by executing a Low Frequency Periodic Signal (LFPS) according to the protocol and returns to the active state after a link recovery phase. Taking the xHCI host controller interface specification as an example, the Transmission Request Block (TRB) is first written to the transmission ring in the computer system memory. After completing the specified memory publishing operation, the endpoint doorbell is written. After receiving the doorbell, the host controller identifies the new task and obtains the TRB through the existing direct memory access, address translation, and consistency path. For OUT transmissions sent from the host to the device, the corresponding payload must also be read according to the data address in the TRB.
[0003] The USB link specification defines the external state transitions and signal timing for exiting a low-power state, while the xHCI specification defines the doorbell, transmission ring, and hardware / software interfaces. However, it does not specify at what point the host controller should read the TRB and payload during LFPS, Recovery, or active states. For implementations that start up only after the link is nearing or entering an active state, or after TRB and first-segment payload preparation are complete, the link may still wait for data from the computer system memory even when it is ready to send packets. This waiting directly increases the response time for short burst traffic from the doorbell to the first packet. For implementations that read multiple descriptors and payloads immediately after all doorbells arrive, invalid memory accesses may occur when the link fails to exit, the task is canceled, or multiple endpoints submit tasks simultaneously. Furthermore, when Double Data Rate (DDR) memory is in a low-power state, memory recovery time may be significantly accelerated.
[0004] Therefore, a mechanism with clear triggering conditions, read boundaries, and undo paths is needed to ensure that early reads only serve real tasks that have been published and need to exit the current state, while guaranteeing that any read failure will not interfere with normal link recovery. Summary of the Invention
[0005] The purpose of this invention is to provide a USB host controller and its hierarchical prefetching method to reduce the first packet response time of short burst services, improve memory access efficiency, and ensure transmission reliability.
[0006] The present invention provides a USB host controller, comprising: The prefetch transaction establishment module is configured to receive the actual endpoint doorbell, determine whether to establish a prefetch transaction based on the port status corresponding to the endpoint doorbell, and generate a transaction identifier when it is determined that a prefetch transaction should be established. The hierarchical prefetch control module is configured to determine the level of prefetch transactions based on the DDR status and link status, and, in conjunction with the control phase corresponding to the exit process, transmit prefetch transactions of different levels to different processing units. The restricted read module is configured to perform descriptor reads on prefetch transactions. The read verification module is configured to perform TRB parsing verification on the prefetched transactions with read descriptors to obtain the descriptor result and first segment payload corresponding to the committable prefetched transactions; The consistency commit module is configured to perform consistency comparisons on the committable prefetch transactions when the link state is in an active state.
[0007] Furthermore, the prefetch transaction establishment module includes: The transaction triggering unit is configured to receive the actual written endpoint doorbell, determine the port status corresponding to the endpoint doorbell through the link state machine, and establish a prefetch transaction if the port status meets the preset conditions. The task identity latching unit is configured to latch the identity information required for this prefetch transaction after the prefetch transaction is established, and record the task version identifier to form a transaction identifier.
[0008] Furthermore, the hierarchical prefetch control module is configured as follows: Set the link to a first low-power state, a second low-power state, a first DDR state, a second DDR state, and a third DDR state; When in the first DDR state and the link state is in the first low-power state or the second low-power state, the prefetch transaction level is determined to be Level 1; when in the second DDR state and the link state is in the second low-power state, the prefetch transaction level is determined to be Level 2; when in the second DDR state and the link state is in the first low-power state, the prefetch transaction level is determined to be Level 3; when in the third DDR state, the prefetch transaction level is determined to be Level 3.
[0009] Furthermore, the hierarchical prefetch control module is also configured as follows: The low-power state exit process is divided into a first control phase, a second control phase, and a third control phase. When the prefetch transaction is at level 1 and the exit process is in the first control phase, the level 1 prefetch transaction is sequentially transmitted to the restricted read module and the read verification module; when the prefetch transaction is at level 2 and the exit process is in the first control phase, the level 2 prefetch transaction is transmitted to the restricted read module; when the level 2 prefetch transaction enters the second control phase from the first control phase, if a preset condition is met, the level 2 prefetch transaction continues to be transmitted to the read verification module; for level 3 prefetch transactions, transmission does not continue, and the link exits according to the current state.
[0010] Furthermore, the read verification module includes: The TRB parsing and verification unit is configured to verify the TRB corresponding to the prefetched transaction. When the verification passes, the payload address is obtained from the TRB. The speculative buffer is configured to store the descriptor result with the transaction identifier and the first segment payload when the verification passes.
[0011] Furthermore, the consistency commit module is configured to: when the comparison is consistent and the first segment payload is complete, submit the descriptor and the first segment payload to the packet builder to complete the first packet construction; when the comparison is consistent but only the descriptor is available, reuse the descriptor result and read the payload through the original path; when the comparison is inconsistent, the prefetch transaction has been rolled back, the verification is abnormal or there is a complete miss, re-execute the reading from the current valid transport ring position.
[0012] Furthermore, the prefetch transaction establishment module is also configured to: treat a low-power exit process of the same port as a shared prefetch cycle, and use a shared quota for multiple real endpoint doorbells arriving within the shared prefetch cycle.
[0013] The present invention also provides a hierarchical prefetching method for a USB host controller, comprising: Step S1: Provide the USB host controller described above; Step S2: Receive the actual endpoint doorbell, determine whether to establish a prefetch transaction based on the port status corresponding to the endpoint doorbell, and generate a transaction identifier when it is determined that a prefetch transaction should be established. Step S3: Determine the level of the prefetch transaction based on the DDR status and link status, and transmit the prefetch transactions of different levels to different processing units in conjunction with the control phase corresponding to the exit process. Step S4: Perform descriptor reading on the prefetch transaction transmitted to the restricted read module; perform TRB parsing and verification on the prefetch transaction transmitted to the read verification module to obtain the descriptor result and first segment payload corresponding to the committable prefetch transaction; Step S5: When the link state reaches the working state, perform a consistency comparison on the committable prefetch transaction.
[0014] Further, step S2 includes: Step S21: Receive the actual written endpoint doorbell, determine the port status corresponding to the endpoint doorbell through the link state machine, and establish a prefetch transaction if the port status meets the preset conditions. Step S22: After the prefetch transaction is established, the identity information required for this prefetch transaction is locked, and the task version identifier is recorded to form a transaction identifier.
[0015] Further, step S3 includes: Step S31: Set the first low-power state U1, the second low-power state U2, the first DDR state, the second DDR state, and the third DDR state of the link; Step S32: When in the first DDR state and the link state is in the first low-power state or the second low-power state, the level of the prefetch transaction is determined to be the first level; when in the second DDR state and the link state is in the second low-power state, the level of the prefetch transaction is determined to be the second level; when in the second DDR state and the link state is in the first low-power state, the level of the prefetch transaction is determined to be the third level; when in the third DDR state, the level of the prefetch transaction is determined to be the third level.
[0016] Furthermore, step S3 also includes: Step S33: Divide the low-power state exit process into a first control phase, a second control phase, and a third control phase; Step S34: When the level of the prefetch transaction is Level 1 and the exit process is in the first control phase, the Level 1 prefetch transaction is sequentially transmitted to the restricted read module and the read verification module; when the level of the prefetch transaction is Level 2 and the exit process is in the first control phase, the Level 2 prefetch transaction is transmitted to the restricted read module; when the Level 2 prefetch transaction enters the Level 2 control phase from the first control phase, if a preset condition is met, the Level 2 prefetch transaction continues to be transmitted to the read verification module; for Level 3 prefetch transactions, transmission does not continue, and the link exits according to the current state.
[0017] Further, step S4 includes: verifying the TRB corresponding to the prefetch transaction; if the verification passes, obtaining the payload address from the TRB, and saving the descriptor result with the transaction identifier and the first segment payload to the speculation buffer.
[0018] Further, step S5 includes: when the comparison is consistent and the first segment payload is complete, submitting the descriptor and the first segment payload to the packet builder to complete the first packet construction; when the comparison is consistent but only the descriptor is available, reusing the descriptor result and reading the payload through the original path; when the comparison is inconsistent, the prefetch transaction has been cancelled, the verification is abnormal or there is a complete miss, re-execute the reading from the current valid transport ring position.
[0019] Further, step S2 includes: treating a single low-power exit process on the same port as a shared prefetch cycle, during which multiple real endpoint doorbells arriving use a shared quota.
[0020] This invention enables the parallel execution of TRB parsing, limited header payload preparation, and low-power state exit processes required for actual transmission tasks. This allows for faster first packet generation when the link enters a working state, shortening the response time from doorbell announcement to first packet transmission for short burst services. By dynamically selecting the prefetch level based on DDR accessibility and link exit progress, it improves the utilization efficiency of exit windows and memory access resources, reducing invalid reads and unnecessary data movement. Through transaction identity verification, isolated caching, consistent commit, and reversible rollback mechanisms, it ensures that prefetch results are used only when the task is valid and the data is consistent, thus balancing low latency, resource control, and transmission reliability. Attached Figure Description
[0021] Figure 1 This is a structural block diagram of a USB host controller according to Embodiment 1 of the present invention.
[0022] Figure 2 This is a schematic diagram illustrating the timing coordination between the exit control phase and different levels of prefetch transactions according to Embodiment 1 of the present invention.
[0023] Figure 3 This is a block diagram showing the actual reading path of the transmission request block and the first segment payload.
[0024] Figure 4 This diagram illustrates the relationship between prefetched transaction states and consistent commit, rollback, and revert operations. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0026] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0027] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0028] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, or the orientation or positional relationship commonly used when the product is in use. These terms are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0029] Furthermore, terms such as "horizontal," "vertical," and "sag" do not imply that components must be absolutely horizontal or suspended, but rather that they can be slightly tilted. For example, "horizontal" simply means that its direction is more horizontal relative to "vertical," and does not mean that the structure must be completely horizontal, but can be slightly tilted.
[0030] In the description of this invention, it should also be noted that, unless otherwise explicitly specified and limited, the terms "set," "install," "connect," and "link" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.
[0031] The following detailed description of some embodiments of the present invention is provided in conjunction with the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0032] Example 1: USB Host Controller like Figure 1As shown, the USB host controller provided in this embodiment includes a prefetch transaction establishment module 10, a hierarchical prefetch control module 20, a restricted read module 30, a read verification module 40, and a consistency commit module 50. Each module is described in detail below.
[0033] The prefetch transaction establishment module 10 is used to receive the actual endpoint doorbell and determine whether to establish a prefetch transaction based on the port status corresponding to the endpoint doorbell. When it is determined that a prefetch transaction should be established, a transaction identifier is generated.
[0034] Specifically, the prefetch transaction establishment module 10 may include a transaction triggering unit 11 and a task identity latching unit 12.
[0035] The transaction triggering unit 11 receives the actual written endpoint doorbell and determines the port state corresponding to the endpoint doorbell through the link state machine. If the following conditions are met: the endpoint is enabled, there is a real task to be processed, the port is in a low-power state of U1 or U2, and executing the task to be processed requires exiting the low-power state and the link state machine has accepted the exit request, then a prefetch transaction is established. If any of the aforementioned conditions are not met, such as the endpoint is unschedulable, there is no real task to be processed, the port is in state U0, or the doorbell is not accepted by the link state machine, then a prefetch transaction is not established.
[0036] In this embodiment, U0, U1, and U2 represent the power management states of the USB 3.2 link layer. U0 represents the operating state that allows normal data transmission, U1 represents a shallow low-power state with a short exit latency, and U2 represents a deeper low-power state with higher energy efficiency and a relatively longer exit latency. Prefetch transactions may include descriptor reads and payload reads derived from those descriptors, but payload reads must not be generated independently of the descriptor verification results.
[0037] In this embodiment, the software first writes to the TRB and data buffer according to the controller's original requirements, then completes the corresponding memory barrier or cache maintenance, and finally writes to the endpoint doorbell. The USB host controller provided in this embodiment does not read the transmission loop content before the doorbell is published.
[0038] The task identity latching unit 12 is used to latch the identity information required for the current prefetch transaction after the prefetch transaction is established, and record the task version identifier to form a transaction identifier. The identity information includes at least the port number, device slot number, endpoint number, flow identifier, transport ring data retrieval position, and loop state. In this embodiment, the transaction identifier is stored in the request table. It should be noted that the transaction identifier is only used to confirm "which doorbell task the returned data belongs to," and does not store the TRB content; the complete TRB is still stored in the transport ring in the system memory. If the controller currently does not have an available transport ring data retrieval position, the original process is directly used, without adding a new speculative access path to obtain that position. When the endpoint stops, resets, the dequeue position changes, or a new task is issued, causing the original task identity to change, the task version identifier is updated accordingly, thus causing the old transaction to become invalid.
[0039] The hierarchical prefetch control module 20 determines the level of the prefetch transaction based on the DDR status and link status, and transmits the prefetch transactions of different levels to different processing units in conjunction with the control phase corresponding to the exit process.
[0040] As described above, the link states for establishing prefetch transactions include U1 and U2. In this embodiment, the DDR state can be divided into M0, M1, and M2. M0 indicates that the DDR is accessible or memory recovery for the pending real task has been completed; M1 indicates that the DDR is in a recoverable state such as self-refresh, and it has accepted access caused by the pending real task and started recovery; M2 indicates that the DDR is deeply inaccessible, the access request has not been accepted, or it is expected that a valid return cannot be formed during this link exit process.
[0041] Referring to Table 1 below, when the DDR state is M0 and the link state is U1 or U2, the prefetch transaction level is determined to be Level 1 (L2); when the DDR state is M1 and the link state is U2, the prefetch transaction level is determined to be Level 2 (L1); when the DDR state is M1 and the link state is U1, the prefetch transaction level is determined to be Level 3 (L0); when the DDR state is M2, regardless of whether the link state is U1 or U2, the prefetch transaction level is determined to be Level 3 (L0). Additionally, when the request queue and speculative buffer have no available resources, the prefetch transaction level is also determined to be Level 3 (L0). Specifically, L2 allows the following prefetch operation: after the TRB verification passes, continue reading the first OUT payload segment with a strict length limit; L1 allows the following prefetch operation: only obtain and verify the first pending TRB; L0 does not prefetch.
[0042] Table 1 In this embodiment, when the DDR state is M0, a Level 1 prefetch transaction is executed, and no additional DDR recovery is triggered by this scheme. When the DDR state is M1, the first descriptor read may cause the DDR to exit self-refresh, but this access is triggered by a real task that has already been published and is limited to the minimum range required to locate and resolve the first TRB; the payload is not read again until the LFPS exit is confirmed. If the memory controller does not accept recovery, the expected return time cannot form a valid overlap, or the controller's internal resources are insufficient, the level of the prefetch transaction is determined to be Level 3 L0, and no early read is issued. In this way, it is avoided to assume that the system memory is definitely available simply because the link is in U1 or U2.
[0043] In this embodiment, the low-power state exit process is divided into a first control phase P0, a second control phase P1, and a third control phase P2. P0 corresponds to the period from when the link state machine receives the exit request and enables LFPS until the exit handshake is confirmed to be successful; P1 corresponds to the Recovery phase after the exit handshake is successful; and P2 corresponds to the U0 commit boundary.
[0044] like Figure 2 As shown, when the prefetch transaction level is Level 1 (L2) and the exit process is in the first control phase (P0), the Level 1 prefetch transaction is sequentially transmitted to the restricted read module 30 and the read verification module 40 to perform TRB reading, TRB parsing verification, and payload reading on the Level 1 prefetch transaction. When the prefetch transaction level is Level 2 (L1) and the exit process is in the first control phase (P0), the Level 2 prefetch transaction is transmitted to the restricted read module 30, where only descriptor reading is performed, and no payload reading request is derived to limit the invalid access range when the exit has not been confirmed. When the Level 2 prefetch transaction enters the second control phase (P1) from the first control phase (P0), it is determined whether the descriptor is valid and whether the identity information corresponding to this prefetch transaction has changed. If the descriptor is valid and the identity information has not changed, the Level 2 prefetch transaction is transmitted to the read verification module 40 to perform TRB parsing verification and payload reading. If the payload reading conditions are not met when performing payload reading, the TRB parsing verification result is retained, and the data is retrieved through the normal path after entering U0. For Level 3 prefetch transactions, regardless of their control phase, no early read is issued, transmission ceases, and the link exits as it was previously in. In this embodiment, the prefetch transaction level and its control phase are stored in the request table.
[0045] The aforementioned phase relationship ensures that the prefetch operation can only utilize the time already present when the link exits, without modifying LFPS, extending Recovery, or delaying the establishment of the U0 state. Whether the prefetch hit occurs only changes whether the first packet data is ready, without altering the completion conditions of the link state machine.
[0046] Reference Figure 3The restricted read module 30 is used to perform descriptor reading on prefetched transactions. Specifically, the descriptor reading starts from the transport ring fetch position in the transaction identifier. The restricted read module 30 reads a minimum data unit covering the target TRB according to the bus granularity supported by the host controller. This minimum data unit can be a single TRB, a cache line, or the minimum burst supported by the original host controller. The read request reaches DDR after passing through normal direct memory access, address translation, cache consistency, and access permission checks. When the descriptor response returns, the corresponding transaction is first found according to the request table, and then the read verification module 40 is entered.
[0047] The read verification module 40 performs TRB parsing verification on the prefetched transaction with the read descriptor, obtaining the descriptor result and first payload corresponding to the committable prefetched transaction. Specifically, the read verification module 40 includes a TRB parsing verification unit 41 and a speculation buffer 42. The TRB parsing verification unit 41 verifies the TRB corresponding to the prefetched transaction, and the verification content includes at least the loop state, TRB type, chain relationship, buffer address, remaining length, and access permissions. Only when all verification content passes the verification does the host controller obtain the payload start address from the TRB and generate the second payload read. The second payload read still reaches DDR through the same memory access path, and the returned data is written to the speculation buffer 42. Therefore, the descriptor address comes from the transport ring position confirmed by the host controller, and the payload address comes from the already verified TRB, with a clear sequential relationship between the two address sources.
[0048] The speculative buffer 42 stores the descriptor result with the transaction identifier and the initial payload. For OUT transmissions from the host to the device, the prefetch length of the initial payload is the minimum of the following four values: the number of bytes required to form the first data packet or the first finite burst, the number of bytes not yet processed by the current TRB, the remaining prefetch quota for this link exit cycle, and the remaining capacity of the speculative buffer. This limitation ensures that the payload read only covers the limited data required to initiate the transmission and does not extend to pre-loading the entire transmission. For IN transmissions from the device to the host, the payload is not prefetched; only the TRB resolution result, the receive buffer address translation result, and the write control information are prepared.
[0049] It should be noted that, in this embodiment, both the complete TRB and OUT data buffers in the transport ring are located in the system memory DDR. The transaction identifier, request table, and speculative buffer stored internally by the host controller are only used for task association, process control, and temporary storage of return results. They do not replace the complete TRB in the system memory, nor do they generate descriptor content when the DDR is inaccessible.
[0050] The consistency commit module 50 is used to perform consistency comparisons on committable prefetch transactions when the link state is U0. When the comparison is consistent and the first segment payload is complete, the descriptor and payload are committed to the packet builder to complete the first packet construction. When the comparison is consistent but only the descriptor is available, the descriptor result is reused and the payload is read through the original path. When the comparison is inconsistent, the transaction has been rolled back, the verification is abnormal, or there is a complete miss, normal reading is re-executed directly from the current valid transport ring position. Among them, consistency comparison refers to re-comparing the port, device slot, endpoint, stream, transport ring data retrieval position, loop state, and task version identifier.
[0051] Reference Figure 4 The prefetch transaction progresses in the direction of descriptor reading—descriptor valid—payload reading—committable. For L1 transactions, after the descriptor becomes valid, it can remain until Recovery confirmation; for IN tasks that do not require prefetching the payload, after the descriptor and receive control information are prepared, it can directly enter the corresponding reusable state, and no state can bypass the U0 consistency commit unit to directly drive transmission.
[0052] When a link exits and times out, enters an error state, or a port is reset, the prefetch transaction enters the rolled-back state and stops generating new requests. When an endpoint stops, resets, the data fetch position on the transport ring changes, or a task is republished, the task version identifier is updated, and old transactions mismatch during consistency comparisons. When descriptor content or access permission checks fail, the prefetch transaction enters the verification exception state. Responses already in the bus can still be returned normally to avoid disrupting the interconnection protocol and request credit, but responses can only be recycled and cannot set the descriptor valid, payload valid, or commit flags. The consistency commit module 50 only processes results that have arrived and does not wait for late responses. Therefore, when this scheme is closed, misses, or fails, the host controller's functional behavior remains consistent with the original process.
[0053] In this embodiment, the address translation, access permissions, cache consistency, and security domain attributes are read in advance using the same methods as normal reads, without gaining additional privileges due to the occurrence of LFPS or Recovery. On non-hardware consistent platforms, the software still performs cache clearing and memory barriers before the doorbell according to the original controller specifications. This embodiment neither reads the TRB prior to the doorbell's release nor replaces the original description compliance check with the data returned in advance.
[0054] In this embodiment, a single U1 / U2 exit on the same port constitutes a shared prefetch cycle. Multiple real doorbells arriving within this shared prefetch cycle share the descriptor request count, the first payload bytes, and the speculative buffer limit. If the limit is insufficient, subsequent tasks are downgraded from L2 to L1 or L0; if the request table is full, the speculative buffer has no free entries, or memory access is not accepted, L0 is used directly. The shared limit provides a defined upper limit to additional reads, preventing the prefetch traffic from growing uncontrollably with the number of doorbells when multiple endpoints submit tasks simultaneously.
[0055] In this embodiment, to avoid duplicate reads, the request table also records the address range and read type that have been sent. When the link phase transitions from P0 to P1, the controller only allows the payload request to be derived if the original descriptor request is completed and the task is still valid, and does not resend the same descriptor request. When the normal path subsequently accesses the same data, the valid result in the speculative buffer can be reused; if the platform memory system supports request merging, it can also be handled by the original merging mechanism, without requiring changes to the minimum dwell time or internal refresh strategy of the DDR controller.
[0056] Example 2: Hierarchical Prefetching Method for USB Host Controllers The hierarchical prefetching method for USB host controllers provided in this embodiment includes the following steps: Step S1: Provide the aforementioned USB host controller.
[0057] Step S2: Receive the actual endpoint doorbell and determine whether to establish a prefetch transaction based on the port status corresponding to the endpoint doorbell. When it is determined that a prefetch transaction should be established, a transaction identifier is generated.
[0058] Specifically, step S2 includes: Step S21: Receive the actual written endpoint doorbell. Determine the port state corresponding to the endpoint doorbell through the link state machine. If the following conditions are met: the endpoint is enabled, there is a real task to be processed, the port is in a low-power state (U1 or U2), executing the task requires exiting the low-power state, and the link state machine has accepted the exit request, then a prefetch transaction is established. If any of the aforementioned conditions are not met, such as the endpoint being unschedulable, there being no real task to be processed, the port being in state U0, or the doorbell not being accepted by the link state machine, then a prefetch transaction is not established.
[0059] Step S22: After the prefetch transaction is established, the identity information required for this prefetch transaction is latched, and the task version identifier is recorded to form a transaction identifier. The identity information includes at least the port number, device slot number, endpoint number, flow identifier, transport ring fetch position, and loop state. In this embodiment, the transaction identifier is stored in the request table.
[0060] Step S3: Determine the level of the prefetch transaction based on the DDR status and link status, and transmit the prefetch transactions of different levels to different processing units in conjunction with the control phase corresponding to the exit process.
[0061] Specifically, determining the level of the prefetch transaction in step S3 includes: Step S31: Set the shallow low-power state with a shorter exit delay as the first low-power state U1 of the link, and the deeper low-power state with a higher energy efficiency and a relatively longer exit delay as the second low-power state U2 of the link; set the state where DDR is accessible or memory recovery for the pending real task is completed as the first DDR state M0; set the state where DDR is in a recoverable state such as self-refresh, and has accepted access caused by the pending real task and has started to recover as the second DDR state M1; set the state where DDR is deeply inaccessible, access requests are not accepted, or it is expected that a valid return cannot be formed in this link exit process as the third DDR state M2.
[0062] Step S32: When the DDR state is M0 and the link state is U1 or U2, the prefetch transaction level is determined to be Level 1 (L2); when the DDR state is M1 and the link state is U2, the prefetch transaction level is determined to be Level 2 (L1); when the DDR state is M1 and the link state is U1, the prefetch transaction level is determined to be Level 3 (L0); when the DDR state is M2, regardless of whether the link state is U1 or U2, the prefetch transaction level is determined to be Level 3 (L0). Additionally, when the request queue and speculative buffer have no available resources, the prefetch transaction level is also determined to be Level 3 (L0). Specifically, L2 allows the following prefetch operation: after the TRB verification passes, continue reading the first OUT payload segment with a strict length limit; L1 allows the following prefetch operation: only obtain and verify the first pending TRB; L0 does not prefetch.
[0063] Step S3, which involves transmitting prefetch transactions of different levels to different processing units, includes: Step S33: Divide the low-power state exit process into a first control phase P0, a second control phase P1, and a third control phase P2; P0 corresponds to the period from when the link state machine receives the exit request and enables LFPS until the exit handshake is confirmed to be successful; P1 corresponds to the Recovery phase after the exit handshake is successful; P2 corresponds to the U0 submission boundary.
[0064] Step S34: When the prefetch transaction's level is Level 1 (L2) and the exit process is in the first control phase (P0), the Level 1 prefetch transaction is sequentially transmitted to the restricted read module 30 and the read verification module 40 to perform TRB reading, TRB parsing verification, and payload reading on the Level 1 prefetch transaction; when the prefetch transaction's level is Level 2 (L1) and the exit process is in the first control phase (P0), the Level 2 prefetch transaction is transmitted to the restricted read module 30, where only descriptor reading is performed, and no payload read request is derived, to limit the invalid access range when the exit is not yet confirmed; when the Level 2 prefetch transaction exits from the first control phase (P0), the second-level ... second-level prefetch transaction exits from the first control phase (P0), the second-level prefetch transaction is transmitted to the restricted read module 30. When the control phase P0 enters the second control phase P1, it determines whether the descriptor is valid and whether the identity information corresponding to this prefetch transaction has changed. If the descriptor is valid and the identity information has not changed, the second-level prefetch transaction is continued to be transmitted to the read verification module 40, where TRB parsing verification and payload reading are performed. If the payload reading conditions are not met during payload reading, the TRB parsing verification result is retained, and the data is retrieved through the normal path after entering U0. For the third-level prefetch transaction, regardless of which control phase it is in, no early read is issued, it is not transmitted, and the link exits according to its existing state. In this embodiment, the prefetch transaction level and its control phase are saved in the request table.
[0065] Step S4: Perform descriptor reading on the prefetch transaction transmitted to the restricted read module 30; perform TRB parsing verification on the prefetch transaction transmitted to the read verification module 40 to obtain the descriptor result and first segment payload corresponding to the committable prefetch transaction.
[0066] Specifically, step S4 includes: In step S41, the restricted read module 30 reads the smallest data unit covering the target TRB according to the bus granularity supported by the host controller. The read request reaches the DDR after passing through normal direct memory access, address translation, cache consistency and access permission checks. When the descriptor response returns, the corresponding transaction is found according to the request table and then enters the read verification module 40.
[0067] Step S42: The verification module 40 reads and verifies the TRB corresponding to the prefetch transaction. If the verification passes, the payload address is obtained from the TRB, and the descriptor result with the transaction identifier and the first payload segment are saved to the speculation buffer. The verification content includes at least the cycle state, TRB type, chain relationship, buffer address, remaining length, and access permissions. For OUT transmissions sent from the host to the device, the prefetch length of the first payload segment is the minimum of the following four: the number of bytes required to form the first data packet or the first finite burst, the number of bytes not yet processed by the current TRB, the remaining prefetch quota for this link exit cycle, and the remaining capacity of the speculation buffer. This limitation ensures that the payload read only covers the limited data required to initiate transmission and does not extend to pre-loading the entire transmission. For IN transmissions sent from the device to the host, the payload is not prefetched; only the TRB parsing result, the receive buffer address translation result, and the write control information are prepared.
[0068] Step S5: When the link state reaches U0, a consistency comparison is performed on the committable prefetch transactions. If the comparison is consistent and the first segment payload is complete, the descriptor and payload are submitted to the packet builder to complete the first packet construction. If the comparison is consistent but only the descriptor is available, the descriptor result is reused and the payload is read through the original path. If the comparison is inconsistent, the transaction has been rolled back, the verification is abnormal, or there is a complete miss, normal reading is re-executed directly from the current valid transport ring position. Here, consistency comparison refers to re-comparing the port, device slot, endpoint, stream, transport ring data retrieval position, loop state, and task version identifier.
[0069] In this embodiment, a single U1 / U2 exit on the same port constitutes a shared prefetch cycle. Multiple real doorbells arriving within this shared prefetch cycle share the descriptor request count, the first payload bytes, and the speculative buffer limit. If the limit is insufficient, subsequent tasks are downgraded from L2 to L1 or L0; if the request table is full, the speculative buffer has no free entries, or memory access is not accepted, L0 is used directly. The shared limit provides a defined upper limit to additional reads, preventing the prefetch traffic from growing uncontrollably with the number of doorbells when multiple endpoints submit tasks simultaneously.
[0070] The beneficial effects of the above embodiments are as follows: (1) By overlapping the TRB parsing of the real task and the limited first segment payload reading with the LFPS and Recovery process, the data preparation gap after the link enters the working state is reduced, and the first packet response time of short burst services is shortened.
[0071] (2) By using hierarchical correspondence, shared prefetch cycle quota and restricted read range, the prefetch strength is matched according to DDR status and exit progress to reduce invalid DDR access, unnecessary load transport and resource occupation, and improve the utilization efficiency of memory access and buffer resources.
[0072] (3) Isolate and verify the data returned early through transaction identification, speculative buffer and consistent commit, and promptly revoke or roll back to the original reading path when exit fails, task changes, verification is abnormal or prefetch miss, so as to avoid misuse of old data and ensure transmission reliability and continuity of original functions.
[0073] The above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of the invention. Various variations can be made to the above embodiments of the present invention. That is, all simple and equivalent changes and modifications made based on the claims and description of this invention fall within the protection scope of the claims of this patent. All aspects not described in detail in this invention are conventional technical content.
Claims
1. A USB host controller, characterized in that, include: The prefetch transaction establishment module is configured to receive the actual endpoint doorbell, determine whether to establish a prefetch transaction based on the port status corresponding to the endpoint doorbell, and generate a transaction identifier when it is determined that a prefetch transaction should be established. The hierarchical prefetch control module is configured to determine the level of prefetch transactions based on the DDR status and link status, and, in conjunction with the control phase corresponding to the exit process, transmit prefetch transactions of different levels to different processing units. The restricted read module is configured to perform descriptor reads on prefetch transactions. The read verification module is configured to perform TRB parsing verification on the prefetched transactions with read descriptors to obtain the descriptor result and first segment payload corresponding to the committable prefetched transactions; The consistency commit module is configured to perform consistency comparisons on the committable prefetch transactions when the link state is in an active state.
2. The USB host controller according to claim 1, characterized in that, The prefetch transaction establishment module includes: The transaction triggering unit is configured to receive the actual written endpoint doorbell, determine the port status corresponding to the endpoint doorbell through the link state machine, and establish a prefetch transaction if the port status meets the preset conditions. The task identity latching unit is configured to latch the identity information required for this prefetch transaction after the prefetch transaction is established, and record the task version identifier to form a transaction identifier.
3. The USB host controller according to claim 1, characterized in that, The hierarchical prefetch control module is configured as follows: Set the link to a first low-power state, a second low-power state, a first DDR state, a second DDR state, and a third DDR state; When the link is in the first DDR state, the first low power state, or the second low power state, the level of the prefetch transaction is determined to be the first level. When in the second DDR state and the link state is in the second low-power state, the prefetch transaction level is determined to be level two; when in the second DDR state and the link state is in the first low-power state, the prefetch transaction level is determined to be level three; when in the third DDR state, the prefetch transaction level is determined to be level three.
4. The USB host controller according to claim 3, characterized in that, The hierarchical prefetch control module is also configured to: The low-power state exit process is divided into a first control phase, a second control phase, and a third control phase. When the level of the prefetch transaction is Level 1 and the exit process is in the first control phase, the Level 1 prefetch transaction is sequentially transmitted to the restricted read module and the read verification module. When the level of the prefetch transaction is the second level and the exit process is in the first control phase, the second level prefetch transaction is transmitted to the restricted read module. When the second level prefetch transaction enters the second control phase from the first control phase, if the preset conditions are met, the second level prefetch transaction is transmitted to the read verification module. For the third level prefetch transaction, transmission is not continued and the link exits according to the current state.
5. The USB host controller according to claim 1, characterized in that, The read verification module includes: The TRB parsing and verification unit is configured to verify the TRB corresponding to the prefetched transaction. When the verification passes, the payload address is obtained from the TRB. The speculative buffer is configured to store the descriptor result with the transaction identifier and the first segment payload when the verification passes.
6. The USB host controller according to claim 5, characterized in that, The consistency submission module is configured as follows: when the comparison is consistent and the first segment payload is complete, the descriptor and the first segment payload are submitted to the package builder to complete the first package construction; when the comparison is consistent but only the descriptor is available, the descriptor result is reused and the payload is read through the original path. When a comparison is inconsistent, a prefetch transaction has been rolled back, a checksum error occurs, or a complete miss occurs, the read is re-executed from the current valid transport ring position.
7. The USB host controller according to claim 1, characterized in that, The prefetch transaction establishment module is also configured to: treat a low-power exit process of the same port as a shared prefetch cycle, and use a shared quota for multiple real endpoint doorbells arriving within the shared prefetch cycle.
8. A hierarchical prefetching method for a USB host controller, characterized in that, include: Step S1: Provide a USB host controller as described in any one of claims 1 to 7; Step S2: Receive the actual endpoint doorbell, determine whether to establish a prefetch transaction based on the port status corresponding to the endpoint doorbell, and generate a transaction identifier when it is determined that a prefetch transaction should be established. Step S3: Determine the level of the prefetch transaction based on the DDR status and link status, and transmit the prefetch transactions of different levels to different processing units in conjunction with the control phase corresponding to the exit process. Step S4: Perform a descriptor read on the prefetch transaction transmitted to the restricted read module; Perform TRB parsing and verification on the prefetch transactions transmitted to the read verification module to obtain the descriptor result and first segment payload corresponding to the committable prefetch transactions; Step S5: When the link state reaches the working state, perform a consistency comparison on the committable prefetch transaction.
9. The hierarchical prefetching method for a USB host controller according to claim 8, characterized in that, Step S2 includes: Step S21: Receive the actual written endpoint doorbell, determine the port status corresponding to the endpoint doorbell through the link state machine, and establish a prefetch transaction if the port status meets the preset conditions. Step S22: After the prefetch transaction is established, the identity information required for this prefetch transaction is locked, and the task version identifier is recorded to form a transaction identifier.
10. The hierarchical prefetching method for a USB host controller according to claim 8, characterized in that, Step S3 includes: Step S31: Set the first low-power state U1, the second low-power state U2, the first DDR state, the second DDR state, and the third DDR state of the link; Step S32: When in the first DDR state and the link state is in the first low-power state or the second low-power state, the level of the prefetch transaction is determined to be the first level; when in the second DDR state and the link state is in the second low-power state, the level of the prefetch transaction is determined to be the second level; when in the second DDR state and the link state is in the first low-power state, the level of the prefetch transaction is determined to be the third level; when in the third DDR state, the level of the prefetch transaction is determined to be the third level.
11. The hierarchical prefetching method for a USB host controller according to claim 10, characterized in that, Step S3 further includes: Step S33: Divide the low-power state exit process into a first control phase, a second control phase, and a third control phase; Step S34: When the level of the prefetch transaction is Level 1 and the exit process is in the first control phase, the Level 1 prefetch transaction is sequentially transmitted to the restricted read module and the read verification module; when the level of the prefetch transaction is Level 2 and the exit process is in the first control phase, the Level 2 prefetch transaction is transmitted to the restricted read module; when the Level 2 prefetch transaction enters the Level 2 control phase from the first control phase, if a preset condition is met, the Level 2 prefetch transaction continues to be transmitted to the read verification module; for Level 3 prefetch transactions, transmission does not continue, and the link exits according to the current state.
12. The hierarchical prefetching method for a USB host controller according to claim 8, characterized in that, Step S4 includes: verifying the TRB corresponding to the prefetch transaction; if the verification passes, obtaining the payload address from the TRB, and saving the descriptor result with the transaction identifier and the first segment payload to the speculation buffer.
13. The hierarchical prefetching method for a USB host controller according to claim 8, characterized in that, Step S5 includes: when the comparison is consistent and the first segment payload is complete, submitting the descriptor and the first segment payload to the packet builder to complete the first packet construction; when the comparison is consistent but only the descriptor is available, reusing the descriptor result and reading the payload through the original path; when the comparison is inconsistent, the prefetch transaction has been cancelled, the verification is abnormal or there is a complete miss, re-execute the reading from the current valid transport ring position.
14. The hierarchical prefetching method for a USB host controller according to claim 8, characterized in that, Step S2 includes: treating a single low-power exit process on the same port as a shared prefetch cycle, and using a shared quota for multiple real endpoint doorbells arriving within the shared prefetch cycle.
