Credit-Based Flow Control Fundamentals
PCIe flow control ensures a transmitter never sends more data than the receiver can buffer. Unlike XON/XOFF or request-grant schemes, credit-based flow control allows continuous transmission as long as credits are available, maximizing link utilization.
The Credit Invariant
At any point in time, the following must hold:
Where:
- CREDITS_CONSUMED: Total credits used by transmitter (modulo counter)
- CREDIT_LIMIT: Maximum credits advertised by receiver via UpdateFC
Credit Counter Mechanics
Both transmitter and receiver maintain 8-bit modulo counters for each credit type. The modulo arithmetic handles wraparound correctly.
Flow Control Initialization Protocol
Before any TLPs can be transmitted, both sides must exchange initial credit values through a two-phase DLLP handshake.
InitFC DLLP Format
| Byte | Field | Description |
|---|---|---|
| 0 | Type | InitFC1-P, InitFC1-NP, InitFC1-Cpl, InitFC2-P, etc. |
| 1 | HdrFC[7:0] | Header credits (lower 8 bits) |
| 2 | DataFC[3:0], HdrFC[11:8] | Data credits lower + Header upper |
| 3 | DataFC[11:4] | Data credits (upper 8 bits) |
Infinite Credits
A receiver advertises "infinite" credits by setting the credit value to 0 during initialization. This means the transmitter never needs to check credits for that type.
When to Use Infinite Credits
- Completion Credits: Completers typically advertise infinite CplH/CplD because completions come from internal processing, not buffer space
- Root Complex: May advertise infinite credits to memory since system memory is "unlimited"
- Non-Posted Data: Often infinite since NP requests rarely carry data
UpdateFC DLLP Scheduling
After initialization, receivers must periodically send UpdateFC DLLPs to replenish transmitter credits.
Deadlock Prevention
PCIe's flow control design inherently prevents deadlock through careful separation of transaction types.
Deadlock Prevention Rules
- Completion Independence: Completions have dedicated credit pool. A Completer can always send completions regardless of request credit state.
- Posted vs Non-Posted: Posted requests cannot be blocked waiting for Non-Posted credits, and vice versa.
- Switch Guarantee: Switches must always be able to forward completions, even if request buffers are full.
- UpdateFC Always Sent: DLLPs (including UpdateFC) are not flow-controlled - they can always be transmitted.
Potential Deadlock Scenario (Prevented by Design)
Scenario: Device A sends MRd to Device B. Device B's buffer is full of requests to Device A. Device A's completion buffer is full.
Why it doesn't deadlock: Completion credits are separate. Even if Device A's request buffers are full, its completion buffer space is independently tracked. Device B can send the completion as long as CplH/CplD credits are available.
Flow Control in Flit Mode
PCIe 6.0+ Flit Mode changes flow control significantly:
- Credit granularity: Changed to 256-byte Flit units instead of 16-byte FC units
- Embedded DLP: Flow control information embedded in Flit structure, not separate DLLPs
- Simplified accounting: Fixed Flit size simplifies credit calculations