MDIO-NETLINK(9)
π mdio-netlink β the netlink hookup to MDIO buses (section 9 of the kernel manual, bestie)
okay so picture this: you're in the kernel manual, section 9, and the page is literally called mdio-netlink. that's the whole vibe. let's get into it π
β¨ SYNOPSIS β¨
#include <linux/mdio-netlink.h>
that's it. that's the include. slay π
π¦ DESCRIPTION π¦
okay so mdio-netlink gives you a direct interface to talk to devices sitting on MDIO buses. like, no middleman, no cap.
but here's the iconic part β the way it stays race-free while running a bunch of reads/writes as one atomic transaction is that your input is a program in byte code form that gets executed inside a little virtual machine living inside mdio-netlink. yes, a whole VM. it's giving main-character energy and honestly it's similar in spirit to how "channel programs" work on some mainframes. iykyk π§
the VM is lowkey minimal β no stack or heap memory, just:
- 8 general purpose registers, each 16-bit
- an implicit program counter (she's just there, doing her thing)
and it serves up this small set of instructions:
READβ read from an MDIO/XMDIO device to a register π«WRITEβ write a register or an immediate value to an MDIO/XMDIO deviceEMITβ emit the contents of a register or an immediate value as an output of the programANDβ store the bitwise AND of two operands to a registerORβ store the bitwise OR of two operands to a registerADDβ store the sum of two operands to a registerJEQβ add an immediate value to the program counter if two operands are equalJNEβ add an immediate value to the program counter if two operands are not equal
that's the whole opcode menu. short, sweet, obsessed πΈ
π HISTORY π
so why does this exist?? because it improves on the traditional MDIO interface that us userspace programs get in Linux, in a few important ways. let me count them π
- MDIO buses are directly addressable. previous solutions relied on at least one Ethernet PHY on the bus being attached to a net device β which is typically not the case when the device is an Ethernet switch, for example. so yeah, that old assumption was not it π
- Complex operations can be performed atomically. the old
ioctl(2)interface only supported a single read or write of a single register. as a result, things like read/mask/write operations and accesses to paged PHYs could not be performed safely. huge L, honestly. now they can. periodt π₯
π SEE ALSO π
mdio(8)β go say hi π«Ά
π AUTHORS π
- Tobias Waldekranz
<tobias@waldekranz.com>β icon, legend, the moment β
and that's the page, bestie!! Linux, dated September 17, 2021 β mwah, catch you in the next manpage ππ
π¦ where this page comes from
- nixos 26.05: mdio-tools 1.3.2
- nixpkgs unstable: mdio-tools 1.3.2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms