Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 36

PCIe Architecture: Layers, Root Complex, Switches, and Endpoints

Recommended resources

Introduction

Welcome to the first lesson in our module on PCIe Subsystem Internals. In our previous module, we concluded by examining how a device driver uses the DMA API to move data between a device and system memory. We treated this as the driver telling the system what to do—perform a data transfer. Now, we will begin to peel back the layers to understand the underlying infrastructure that makes this communication possible. This lesson focuses on the how and where of that communication: the PCI Express bus itself.

Our goal for this lesson is to describe the PCIe layered architecture, including the root complex, switches, and endpoints. By the end, you'll have a solid conceptual map of a PCIe system's physical topology and the logical protocol layers that govern communication, providing the essential foundation for our deep dive into PCIe drivers and enumeration in the lessons to come.


1. The PCIe Topology: A Hierarchical System

Unlike its predecessor, the parallel PCI bus, which was a shared bus where multiple devices listened on the same set of wires, PCI Express (PCIe) uses a point-to-point topology. Each connection, called a Link, connects exactly two devices. To build a system with multiple devices, these links are arranged in a tree-like hierarchy.

The main components that form this hierarchy are:

  • Root Complex (RC): The root of the tree. It connects the CPU and main memory to the PCIe fabric. You can think of it as the bridge between the processor's world and the PCIe world. The RC is typically integrated into the CPU or the motherboard's chipset.
  • Endpoint (EP): The leaves of the tree. These are the actual devices you want to use, such as a graphics card, a network interface card (NIC), an NVMe SSD, or a custom device on an expansion card.
  • Switch: The branches of the tree. A switch is used to expand the number of available PCIe ports. It has one "upstream" port connecting towards the Root Complex and multiple "downstream" ports connecting to Endpoints or even other switches.

To get a clear definition of these core components and see how they fit together, please watch the following segment.

Overview of PCI(e) Subsystem - Kishon Vijay Abraham, Texas Instruments

This video from The Linux Foundation provides concise definitions for the fundamental building blocks of a PCIe system.

Watch the segment from 03:39 to 04:56. It clearly defines the Root Complex, PCI Endpoint, Bridges, and Switches.

This hierarchical structure is fundamental to how PCIe works. Any communication between two Endpoints must travel "upstream" towards a common point (a Switch or the Root Complex) and then "downstream" to the target.

The following article provides a clear textual description and a helpful diagram of this topology.

PCI Express Advanced Error Reporting – An Introduction

This article from Oracle Blogs, 'PCI Express Advanced Error Reporting – An Introduction', reinforces the concepts of the PCIe hierarchy with clear text and a simple diagram.

Please read the initial section titled 'A Quick PCI Express Primer', focusing on the definitions and Figure 2, which illustrates the tree-like hierarchy.


2. The Three Layers of PCIe Communication

Now that we understand the physical arrangement of components, let's explore how they communicate. The PCIe specification defines a three-layer protocol stack. Data that needs to be sent is packaged at the top layer and passed down, with each layer adding its own information, until it is sent as electrical signals over the physical link. The receiving device reverses the process.

This layered approach is a classic engineering solution that separates concerns, which should be familiar from your work with complex embedded systems and network stacks.

PCIe Layered Architecture: Root Complex vs. End Point
This diagram illustrates the symmetric, layered architecture of PCIe communication between a Root Complex and an Endpoint. Packets originate in the Transaction Layer, are prepared for reliable transmission by the Data Link Layer, and are finally sent as electrical signals by the Physical Layer.

Here is a breakdown of each layer's primary responsibility:

  1. Transaction Layer: This is the highest layer and the one that software most directly interacts with. Its job is to create and interpret Transaction Layer Packets (TLPs). These packets are requests or completions for specific actions, such as:

    • Memory Read/Write
    • I/O Read/Write
    • Configuration Read/Write (used for device discovery, which we'll cover next lesson)
    • Messages (for events like interrupts and errors)
      When your driver initiates a DMA transfer, the hardware is ultimately creating and processing TLPs at this layer.
  2. Data Link Layer: This middle layer acts as a reliable transport service for the Transaction Layer. Its key responsibilities are to ensure data integrity and manage flow control. It takes TLPs from the layer above and adds:

    • A sequence number to track packets.
    • A Link CRC (LCRC) for error detection.
      This layer is responsible for acknowledging (ACK) correctly received packets and requesting re-transmission (NAK) for corrupted ones.
  3. Physical Layer: This is the lowest layer, responsible for the actual transmission of data over the physical link. It handles:

    • Serializing the parallel data from the Data Link Layer into a serial bitstream.
    • Encoding the data to ensure DC balance and provide a guaranteed number of signal transitions for clock recovery (e.g., 8b/10b or 128b/130b encoding).
    • The electrical signaling across one or more Lanes.
    • Link initialization and training (negotiating link width and speed).

To see how these layers work in concert, the following reading provides an excellent summary.

PCI Express Advanced Error Reporting – An Introduction

Let's return to the 'PCI Express Advanced Error Reporting' article. This section provides a concise explanation of each layer's role and includes a diagram showing how a packet flows through the stack.

Please read the text following 'Figure 2: Example PCI Express hierarchy' up to the end of the primer. Focus on the bulleted list describing the three layers and the concepts shown in Figure 3.


3. Interview Scenario: Deconstructing a System

To solidify these concepts, let's analyze a typical scenario you might encounter in a high-level interview.

Scenario:
You are examining the architecture of a modern server. It contains a CPU, two NICs for redundant networking, and four NVMe SSDs configured in a RAID array for high-speed storage. All peripherals are PCIe-based.

Questions:

  1. Describe a likely PCIe topology for this system. Identify the Root Complex, the Endpoints, and where a Switch would be necessary.
  2. Trace the high-level journey of a single "Memory Write" TLP from the CPU to one of the NVMe SSDs. Describe what happens at each of the three protocol layers at both the source (Root Complex) and destination (NVMe Endpoint).
Click for Analysis
  • 1. System Topology:

    • Root Complex (RC): The CPU's integrated Root Complex is the top-level component.
    • Endpoints (EPs): There are six endpoints in total: the two NICs and the four NVMe SSDs.
    • Switch: A single Root Complex is unlikely to have six downstream ports. Therefore, it is almost certain that one or more PCIe Switches are used. A common design would be for the RC to have a high-speed (e.g., x16) link to a main Switch. This Switch would then provide multiple downstream ports (e.g., x8 or x4) to connect to the six Endpoints.
  • 2. TLP Journey (CPU to NVMe SSD):

    1. CPU/Driver Action: A storage driver in the kernel initiates a DMA write to the NVMe device.
    2. At the Root Complex (Source):
      • Transaction Layer: Constructs a "Memory Write" TLP. This packet contains the source ID (from the RC), the destination address (of the NVMe), the memory address to write to on the NVMe device, and the data payload itself.
      • Data Link Layer: Takes the TLP, adds a sequence number and a Link CRC (LCRC), and passes it down.
      • Physical Layer: Encodes the packet (e.g., using 128b/130b encoding), serializes it, and transmits it as electrical signals across the physical lanes toward the Switch.
    3. At the Switch (Intermediate): The switch receives the packet, fully processes it up to the Transaction Layer to read the destination address, and then forwards it out the correct downstream port towards the target NVMe device. The TLP is then passed back down the layers for re-transmission.
    4. At the NVMe Endpoint (Destination):
      • Physical Layer: Receives the electrical signals, de-serializes them, and decodes them back into a packet.
      • Data Link Layer: Verifies the LCRC. If it's correct, it schedules an ACK packet to be sent back to the RC. It then strips the sequence number and LCRC and passes the clean TLP up.
      • Transaction Layer: Receives and decodes the TLP. It recognizes it as a Memory Write request, extracts the address and data, and passes the request to the device's internal logic to write the data to its flash memory.

Conclusion

In this lesson, we established the foundational model of the PCIe subsystem. You now have a mental map of how PCIe devices are physically interconnected and how they communicate through a structured, layered protocol.

Key Takeaways:

  • PCIe Topology: It is a hierarchical, point-to-point system, not a shared bus. The core components are the Root Complex (CPU bridge), Endpoints (devices), and Switches (port expanders).
  • Layered Architecture: Communication is managed by three distinct layers:
    • The Transaction Layer creates packets for memory, I/O, and configuration operations.
    • The Data Link Layer ensures reliable, error-checked delivery of those packets.
    • The Physical Layer handles the electrical signaling and data encoding on the wire.

This understanding is critical. As we move forward, every concept—from device discovery to interrupt handling—builds upon this model of a hierarchical topology and a layered protocol.

In our next lesson, we will address a fundamental question: When a computer boots up, how does the kernel know what PCIe devices are present? We will explore PCIe enumeration and how the kernel discovers and configures devices during boot.