Unlocking Board‑Level Communication: A Practical Guide to MCTP and AF_MCTP on Linux
This article explains the Management Component Transport Protocol (MCTP), its Linux address family implementation AF_MCTP, driver and network configuration steps, socket programming examples, debugging techniques, and real‑world applications for component monitoring and management in firmware ecosystems.
MCTP Overview
MCTP (Management Component Transport Protocol) is a media‑agnostic transport protocol used for communication between board components such as BMC, NIC, and HBA/RAID cards. It works over various physical links (USB, I2C, PCIe, RMII) and defines an Endpoint Identifier (EID) similar to an IP address for device identification.
Common hardware bindings include PCIe VDM, I2C, and I3C, with specifications for message transmission over SMBus (including PEC checks). MCTP provides a lightweight network‑like model for board‑level devices.
AF_MCTP Introduction
AF_MCTP is a Linux address family that exposes MCTP through the standard socket API, similar to AF_UNIX or AF_INET. Kernel versions 5.15 and 5.18 implement the core MCTP protocol and the I2C hardware binding driver respectively, enabling socket‑based communication with board components.
AF_MCTP Advantages
Application code can ignore hardware‑binding details and simply specify the target EID.
Programming is simplified and more flexible.
Built‑in debugging allows packet capture and analysis just like network debugging.
Configuration Steps
Configure Driver
Kernel must be version > 5.18 and enable the following options:
<code>CONFIG_MCTP=y
CONFIG_MCTP_TRANSPORT_I2C=y</code>Device‑tree example:
<code>&i2c2 {
status = "okay";
multi-master;
mctp-controller;
mctp@10 {
compatible = "mctp-i2c-controller";
reg = <(0x10 | I2C_OWN_SLAVE_ADDRESS)>;
};
}</code>Configure Network
Assign an EID to the local MCTP interface:
<code>mctp addr add 8 dev mctpi2c3</code>Use Socket
<code>/* create the MCTP socket */
sd = socket(AF_MCTP, SOCK_DGRAM, 0);
/* populate the remote address information */
addr.smctp_family = AF_MCTP; /* MCTP family */
addr.smctp_addr.s_addr = 9; /* remote endpoint ID */
addr.smctp_type = 2; /* encapsulated protocol type, e.g., NCSI */
addr.smctp_tag = MCTP_TAG_OWNER; /* kernel allocates a tag */
/* send the MCTP message */
rc = sendto(sd, buf, sizeof(buf), 0, (struct sockaddr *)&addr, sizeof(addr));
/* receive a message */
len = recvfrom(sd, buf, sizeof(buf), MSG_TRUNC, (struct sockaddr *)&addr, &addrlen);
</code>Debugging AF_MCTP
Packet capture with tcpdump :
<code>tcpdump -i mctpi2c3 -w /tmp/mctp.pcap</code>Analysis can be performed in Wireshark, which currently supports MCTP Control, NVME‑MI over MCTP, and NCSI over MCTP protocols.
AF_MCTP Applications
NIC/optical module temperature monitoring
NIC asset information management
Link status monitoring
HBA/HDD temperature monitoring
HBA/HDD asset management
Future work includes integrating PLDM for out‑of‑band firmware updates.
Component Initiative
Current challenges in component management include non‑standard command implementations, OEM inconsistencies, and varied out‑of‑band protocols. The initiative promotes unified command sets and standardized testing to reduce integration effort and improve compatibility.
ByteDance SYS Tech
Focused on system technology, sharing cutting‑edge developments, innovation and practice, and analysis of industry tech hotspots.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.