MDIO-NETLINK(9)

πŸ“¦ version 1.3.2, in nixos 26.05, nixpkgs unstable

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 device
  • EMIT β€” emit the contents of a register or an immediate value as an output of the program
  • AND β€” store the bitwise AND of two operands to a register
  • OR β€” store the bitwise OR of two operands to a register
  • ADD β€” store the sum of two operands to a register
  • JEQ β€” add an immediate value to the program counter if two operands are equal
  • JNE β€” 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