SkillPilotAI

devlink

devlink (iproute2) configures a whole smart NIC or switch ASIC at device level: firmware, eswitch mode, ports, subfunctions, rate limits, buffers and health. ip and ethtool see one netdev like eth0; devlink sees the physical device behind it.

60.1 What it does, where it runs

  • Device-level configuration of smart NICs and switch ASICs, independent of any single network interface.
  • Linux only: iproute2 plus a driver with devlink support. No Windows or macOS version.
  • Syntax: devlink [OPTIONS] OBJECT { COMMAND | help }.
  • Device handle: DEV = pci/0000:01:00.0 (BUS/ADDRESS); port handle DEV/PORT_INDEX.
devlink vs ip/ethtool
  1. 1.A server has a smart NIC with a small switch inside; VFs of VM 1 and VM 2 plug into it

  2. 2.ip and ethtool see only one netdev, e.g. eth0

  3. 3.devlink handles the whole physical device pci/0000:01:00.0

  4. 4.devlink dev info goes over netlink to the driver

  5. 5.The driver replies with firmware versions (fixed, running, stored)

60.2 eswitch modes: legacy vs switchdev

  • legacy: VM 1 -> hidden switch inside the NIC -> VM 2, forwarded by MAC and VLAN. The host never sees this traffic, so Open vSwitch rules do not apply.
  • switchdev: every VF gets a representor netdev on the host.
  • The first packet goes NIC -> host, an Open vSwitch rule decides, and the rule is offloaded into the NIC hardware.
  • Next packets go NIC -> VM 2 directly: control stays with the host, speed comes from hardware.
switchdev: first packet to host, rest offloaded
  1. 1.devlink dev eswitch set DEV mode switchdev

  2. 2.Host gets VF0 rep and VF1 rep netdevs

  3. 3.First packet VM 1 -> NIC -> host (representor)

  4. 4.Open vSwitch rule decides and is offloaded to the NIC

  5. 5.Following packets VM 1 -> NIC -> VM 2 in hardware

Pointlegacyswitchdev
Who forwardsHidden NIC switch (MAC + VLAN)OVS rules on host, offloaded to NIC
Host visibilitySees nothingRepresentor netdev per VF
Policy controlNone from hostFull (OVS / tc flower)
SpeedHardwareHardware after the first packet

60.3 Practical: version, help and JSON

Terminal
devlink -Vdevlink helpdevlink -jp dev show
Output
$ devlink -Vdevlink utility, iproute2-6.9.0$ devlink helpUsage: devlink [ OPTIONS ] OBJECT { COMMAND | help }       devlink [ -f[orce] ] -b[atch] filename -N[etns] netnsnamewhere  OBJECT := { dev | port | lc | sb | monitor | dpipe | resource | region | health | trap }       OPTIONS := { -V[ersion] | -n[o-nice-names] | -j[son] | -p[retty] | -v[erbose] -s[tatistics] -[he]x }$ devlink -jp dev show{    "dev": {}}
  • help lists all objects; OBJECT help shows that object's commands.
  • -j -p JSON is empty: this Docker kernel has no smart NIC and no netdevsim driver.

60.4 Global options: batch, force and -N

Terminal
cat /tmp/cmds.txtdevlink -batch /tmp/cmds.txtdevlink -b /tmp/cmds.txtdevlink -f -b /tmp/cmds.txtip netns add n060nsdevlink -N n060ns dev showdevlink -N nope dev show
Output
$ cat /tmp/cmds.txtdev showdev show pci/0000:01:00.0port show$ devlink -batch /tmp/cmds.txtCannot open file "atch" for reading: No such file or directory$ devlink -b /tmp/cmds.txtkernel answers: No such deviceCommand failed /tmp/cmds.txt:2$ devlink -f -b /tmp/cmds.txtkernel answers: No such deviceCommand failed /tmp/cmds.txt:2kernel answers: No such deviceCommand failed /tmp/cmds.txt:3$ ip netns add n060ns$ devlink -N n060ns dev show$ devlink -N nope dev showCannot open network namespace "nope": No such file or directory
  • -batch is read as -b with a file named atch: use -b or --batch.
  • -b stops at the failure on line 2; -f keeps going and runs line 3 too.
  • -N runs the command inside a network namespace.
Output
-V  --Version       print version, exit-b  --batch FILE    commands from a file-b -                commands from stdin-f  --force         go on after errors-n  --no-nice-names port ids, not ifnames-j  --json          JSON output-p  --pretty        indented JSON (-j)-v  --verbose       verbose output-s  --statistics    counters (trap show)-N  --Netns NAME    switch netns first-i  --iec           rates in IEC (1Ki=1024)-x  --hex           region dump in hex-batch / -force     fail in 6.9: -b / -f

60.5 Object dev: show and eswitch

Terminal
ip -br addr show eth0ethtool -i eth0devlink dev showdevlink dev show pci/0000:01:00.0devlink dev eswitch set pci/0000:01:00.0 \  mode switchdev
Output
$ ip -br addr show eth0eth0@if995       UP             192.168.80.10/24$ ethtool -i eth0driver: vethversion: 1.0firmware-version:bus-info:$ devlink dev show[exit 0]$ devlink dev show pci/0000:01:00.0kernel answers: No such device$ devlink dev eswitch set pci/0000:01:00.0 \  mode switchdevkernel answers: No such device
  • The container's eth0 is a veth with empty bus-info, so dev show prints nothing (exit 0).
  • Any PCI handle gets kernel answers: No such device.
Output
dev show              all devicesdev show DEV          one devicedev eswitch show DEV  mode, inline, encapeswitch set DEV mode legacy                      VFs via the NIC switcheswitch set DEV mode switchdev                      representors + offloadinline-mode none      no headersinline-mode link      L2 headers inlineinline-mode network   up to L3 headersinline-mode transport up to L4 headersencap-mode none       encapsulation offencap-mode basic      encapsulation onDEV = pci/0000:01:00.0 (BUS/ADDRESS)
  • On a real NIC, set commands run with sudo.
  • inline-mode = how many headers the VF driver puts in the descriptor so the eswitch can match (link = L2, transport = L4); encap-mode basic turns on tunnel encapsulation.

60.6 dev param, reload, info, flash

Output
dev param show [DEV name max_macs]param set DEV name P value V cmode runtime                     applies nowcmode driverinit     after dev reloadcmode permanent      in NVM, hard reset-- dev reload --dev reload DEV       default driver_reinitreload DEV netns ns1 | netns 1234action driver_reinit params + resourcesaction fw_activate   pending firmware onlimit no_reset       no reset, no link flap-- dev info / flash / selftests --dev info DEV          fixed, running, storeddev flash DEV file firmware.bin                      from /lib/firmware  component fw.mgmt   one image onlydev selftests show DEVdev selftests run DEV id flash

Kernel docs example output:

Output
$ devlink dev reload pci/0000:82:00.0 action fw_activatereload_actions_performed:  driver_reinit fw_activate
cmodeWhen the value applies
runtimeImmediately
driverinitAfter devlink dev reload
permanentSaved in NIC memory (NVM), after a hard reset
  • dev info: running = firmware in use now, stored = next firmware in flash.
  • dev flash path is relative to /lib/firmware; then reload action fw_activate turns on the pending firmware.
  • selftests show / run list and run built-in device tests.

60.7 Object port: show, split, subfunctions

Output
port show            all portsport show DEV/1      one portport set DEV/1 type eth   Ethernetport set DEV/1 type ib    InfiniBandport set DEV/1 type auto  device decidesport split DEV/1 count 4  100G = 4 lanesport unsplit DEV/1   any port of the groupport health show DEV/1 reporter tx-- port add / del / function --port add DEV flavour pcisf pfnum 0 sfnum 88flavour pcipf | pcisf    PF or subfunctionport del DEV/1      first state inactivefunction set DEV/1 hw_addr 00:00:00:11:22:33function set DEV/1 state active | inactive

Kernel docs example output:

Output
$ devlink port show pci/0000:06:00.0/2pci/0000:06:00.0/2: type eth netdev enp6s0pf0vf1 flavour pcivf pfnum 0 vfnum 1  function:    hw_addr 00:00:00:00:00:00$ devlink port function set pci/0000:06:00.0/32768 hw_addr 00:00:00:00:88:88$ devlink port show pci/0000:06:00.0/32768pci/0000:06:00.0/32768: type eth netdev enp6s0pf0sf88 flavour pcisf pfnum 0 sfnum 88  function:    hw_addr 00:00:00:00:88:88
  • port 2 is a VF port with flavour pcivf.
  • port split breaks a 100G port into 4 breakout ports; unsplit works on any port of the group.
  • port add creates a subfunction (SF 88 got port 32768); set hw_addr first, then state active; set state inactive before deleting.

60.8 port function rate

Terminal
devlink port function rate helpdevlink port function rate set \  pci/0000:03:00.0/1 tx_max 1gbitdevlink port function rate set \  pci/0000:03:00.0/1 tx_max 1gbyte
Output
$ devlink port function rate help       devlink port function rate set DEV/{ PORT_INDEX | NODE_NAME }               [ tx_share VAL ][ tx_max VAL ][ tx_priority N ][ tx_weight N ][ { parent NODE_NAME | noparent } ]       VAL - float or integer value in units of bits or bytes per second (bit|bps)       and SI (k-, m-, g-, t-) or IEC (ki-, mi-, gi-, ti-) case-insensitive prefix.       Bare number, means bits per second, is possible.$ devlink port function rate set \  pci/0000:03:00.0/1 tx_max 1gbitkernel answers: No such device$ devlink port function rate set \  pci/0000:03:00.0/1 tx_max 1gbyteInvalid rate value: "1gbyte"
  • Limits TX speed of a VF/SF port: tx_share (min), tx_max, tx_priority, tx_weight.
  • 1gbit is accepted and reaches the kernel (no device); 1gbyte is rejected by devlink itself: not a valid unit.
Output
rate show [DEV/1 | DEV/grp1]  leaf / noderate set DEV/1 tx_share 2Mbit   min sharerate set DEV/1 tx_max 10Mbit    max TXrate set DEV/1 parent grp1 | noparentrate add DEV/grp1 tx_max 30Mbit   noderate del DEV/grp1   fails with children-i rate show  IEC,  -jp = bytes/sec-- Rate VALUE units --1000000 | bit       bits per secondkbit mbit gbit tbit       SI bitsbps kbps mbps gbps tbps   bytes per seckibit mibit gibit tibit   IEC (1024)0 = unlimited, units case-insensitive
  • A leaf is a port, a node is a group you create; parent limits apply to all children.
  • bit = bits/s, bps = bytes/s; ki/mi prefixes are 1024-based; 0 = unlimited.

60.9 monitor

Terminal
devlink monitor helptimeout 3 devlink monitor alltimeout 3 devlink monitor dev port health
Output
$ devlink monitor helpUsage: devlink monitor [ all | OBJECT-LIST ]where  OBJECT-LIST := { dev | port | lc | health | trap | trap-group | trap-policer }$ timeout 3 devlink monitor all[exit 143]$ timeout 3 devlink monitor dev port health[exit 143]
  • monitor first, then an object list (dev port health) or all.
  • No event in 3 s in the lab, so timeout stopped it (exit 143); on a real server port changes and health errors print live.

60.10 Debugging: health and trap

Trap: an ASIC drop reaches the CPU
  1. 1.Host sends a packet with a multicast source MAC

  2. 2.The switch ASIC drops it in hardware; Linux never knows

  3. 3.trap set ... source_mac_is_multicast action trap

  4. 4.The ASIC now sends a copy to the CPU

  5. 5.devlink -s trap show displays the counters

  6. 6.Firmware crash: a health reporter counts the error and runs recovery

Output
health show [DEV/1 reporter tx]  statushealth recover DEV reporter fw_fatalhealth diagnose DEV reporter fwhealth dump show DEV/1 reporter txhealth dump clear DEV/1 reporter txhealth test DEV reporter fw   test eventhealth set DEV reporter fw_fatal  grace_period 3500   gap between recoveries  auto_recover true | false  auto_dump true | false-- trap --trap show [DEV trap TRAP]   -vs = statstrap set DEV trap source_mac_is_multicast  action trap    only to the CPU  action drop    drop, no CPU copy  action mirror  forward + CPU copytrap group set DEV group l2_drops  action trap | drop | mirror  policer 1 | nopolicer   bind / unbindtrap policer set DEV policer 1  rate 1000      packets per second  burst 128      burst (packets)
  • Reporters track one error type (TX queue, fatal firmware); diagnose = current state; dump show = last saved dump for the vendor.
  • grace_period is the minimum gap between two auto recoveries.
  • trap actions: trap = only to CPU, drop = drop in hardware, mirror = forward + copy to CPU; a policer limits rate/burst to the CPU.

60.11 sb, resource, region, dpipe, lc

Output
sb show [DEV sb 0]       default sb 0sb pool show [DEV pool 0]   size, thtypesb pool set DEV pool 0 size 12401088  thtype static | dynamic   bytes / alphasb port pool set DEV/1 pool 0 th 15sb tc bind set DEV/1 tc 0 type ingress  pool 0 th 9              TC to poolsb occupancy snapshot DEV  snapshot firstsb occupancy show DEV | DEV/1   cur/maxsb occupancy clearmax DEV  reset max-- resource / region --resource show DEV        resources + sizeresource set DEV path /kvd/linear size 98304                         apply with dev reloadregion new DEV/cr-space [snapshot 5]region dump DEV/cr-space snapshot 1region read DEV/cr-space snapshot 1  address 0x10 length 16   16 bytes-- dpipe / lc --dpipe table show DEV [name mlxsw_erif]dpipe table set DEV name mlxsw_erif  counters_enabled true | falselc set DEV lc 1 type 16x100G   provisionlc set DEV lc 1 notype    clearlab: sb/region/health/trap/lc show = empty
  • sb (shared buffer) = ASIC packet memory shared by all ports; pools and thresholds limit each port/TC; snapshot before reading occupancy.
  • resource = ASIC table sizes (apply with dev reload); region = device memory snapshots (cr-space) for debugging.
  • dpipe = dataplane pipeline tables; lc = line cards of a modular switch.
  • In the lab all these show commands return empty (no hardware).

60.12 Common mistakes

  • Myth: devlink = ethtool. ethtool handles one netdev (speed, offloads of eth0); devlink controls the whole PCI device: firmware, eswitch, ports.
  • So the eswitch mode cannot be changed with ethtool.
  • Setting a param with cmode driverinit and expecting it to apply: run devlink dev reload.
  • Using -batch / -force in iproute2 6.9: use -b / -f.
  • Deleting an SF port while its function is still active.

60.13 Interview tips

  • OVS offload on an SR-IOV NIC: devlink dev eswitch set DEV mode switchdev, add the VF representors to an OVS bridge, enable hardware offload.
  • Debug with devlink health show and devlink -s trap show.
  • cmode: runtime = now, driverinit = after reload, permanent = NVM after hard reset.
  • Firmware update: devlink dev flash, then devlink dev reload action fw_activate.