Back to all posts
14 min read

The Jenga Tower of Drivers

The Jenga Tower of Drivers

The world used to be slow. A breakthrough in hardware came once a year if you were lucky, once a decade if you were honest. Software moved at the same pace, and that was fine. If you shipped a storage interface in 1986, you could expect it to still be plugged into machines in 2006.

So the industry learned one lesson and learned it hard: never break the interface. Whatever new thing you build, make it pretend to be the old thing. The old drivers keep working and nobody has to rewrite anything.

That lesson built a tower. Every generation of hardware added a block on top, carefully, without touching the blocks underneath. We have been playing Jenga with our drivers for forty years, and the tower is now tall enough that nobody remembers what the bottom blocks were for.

The Disk That Lies

I learned this from a pile of used drives. After the Chia crash, the farms that had been filling disks for that coin started dumping their hardware, and I bought a stock of it for cheap: 30 petabytes of second-hand storage. Sorting through it, I kept opening mSATA SSDs and budget NVMe sticks, and I kept finding the same low-end Chinese NAND on both.

The controllers were different, of course, and a high-end NVMe drive carries far better flash than anything in that pile. At the budget end, though, the memory was identical. One drive introduced itself to the operating system as a hard disk. The other one did not. Even the mSATA connector is part of the act: it borrows the physical shape of a mini PCIe card and then speaks SATA over it. Same flash underneath, with a different controller and a different costume on top.

It took me a while to understand how deep that costume goes.

A SATA SSD is a chip full of flash memory pretending to be a spinning disk. It speaks ATA, a command set designed for platters and read heads. It sits behind AHCI, a controller interface Intel published in 2004 for hard drives. AHCI gives you one command queue with room for 32 commands, because a hard drive with a mechanical arm physically cannot do more than one thing at a time. Queueing more would be pointless.

On FreeBSD 16, that drive shows up as ada0. It goes through ahci(4), then CAM, our Common Access Method layer, which was built around SCSI in the 1990s and has carried every disk since. The kernel treats the SSD exactly like the 500 GB spinner it replaced, because that is what the SSD told it to do.

Flash has no arm. It has dozens of independent dies that can all work at once. None of that parallelism is visible to the operating system, because the drive is busy pretending to have one.

The act goes deeper than the protocol. Flash cannot overwrite a page in place: it has to erase a whole block first, and erase blocks are measured in megabytes. The operating system thinks in 512-byte sectors, a number inherited from floppy disks. So every SSD carries a small computer, the Flash Translation Layer, whose entire job is to maintain the illusion. It remaps every write and runs garbage collection behind your back.

The lie was so complete that the drive had no idea when you deleted a file. A hard drive never needed to know, so the protocol never told it. The industry had to bolt on TRIM so the filesystem could whisper to the drive which blocks were actually free. TRIM is a block added to the tower to fix a problem caused by the block below it.

NVMe was supposed to be the clean break. Version 1.0 shipped in March 2011, designed for flash from day one: up to 65,535 queues with 65,536 commands each, one per CPU core if you like. It threw out AHCI completely.

And then we dressed it up again ourselves. FreeBSD first drove NVMe disks with nvd(4), a thin driver that went straight to the block layer. Since FreeBSD 14.0 the default is nda(4), which routes NVMe through CAM. The protocol designed to escape the SCSI era now reaches your filesystem through a SCSI-era framework, and each namespace on the drive is reported as a CAM LUN. There are good reasons for it: one error path for every disk, and camcontrol works on all of them. Every block in this tower was laid for reasons just as good.

The drive kept its own lie too. An NVMe drive still presents itself as a flat array of logical blocks, and the FTL still sits inside, hiding the real geometry and doing its own garbage collection on its own schedule. ZFS is copy-on-write: it never overwrites a block in place, which is precisely what flash wants. It also does its own space management. So you get two garbage collectors that cannot see each other, fighting over the same flash. Write amplification is the bill.

The honest interface exists. NVMe Zoned Namespaces were ratified in June 2020: the drive exposes its zones, the host writes them sequentially, and the FTL mostly goes away. Flexible Data Placement followed in 2023, pushed by the hyperscalers together with Samsung, as a softer version for people who did not want to take on garbage collection themselves. Both exist because hyperscalers did the math on the lie and found it expensive.

Your laptop uses neither and is still talking to a disk costume.

flowchart TB
    subgraph sata["SATA SSD on FreeBSD 16"]
        S1[ZFS] --> S2["ada(4) via CAM"]
        S2 --> S3["ahci(4): 1 queue, 32 commands"]
        S3 --> S4[Flash Translation Layer]
        S4 --> S5[NAND flash]
    end
    subgraph nvme["NVMe SSD on FreeBSD 16"]
        N1[ZFS] --> N2["nda(4) via CAM"]
        N2 --> N3["nvme(4): up to 65,535 queues"]
        N3 --> N4[Flash Translation Layer]
        N4 --> N5[NAND flash]
    end
    subgraph zns["NVMe with Zoned Namespaces"]
        Z1[Zone-aware filesystem] --> Z2["Zones, written sequentially"]
        Z2 --> Z3[NAND flash]
    end

Every Device Is a Computer Now

Storage hides its computer. WiFi cards and GPUs stopped hiding theirs, and once you notice that, their drivers turn out to be the same driver.

There are only two ways to drive a complex device. Either the host does the work and the device is a dumb pipe, or the device has its own CPU running its own firmware and the host sends it requests. WiFi people call these SoftMAC and FullMAC. In SoftMAC the operating system runs the 802.11 MAC layer and builds the frames itself. In FullMAC the chip does all of it and the driver mostly forwards commands.

FreeBSD’s wireless stack, net80211, grew up in the SoftMAC world. Our native drivers like ath(4) and iwm(4) hand it raw frames and let it do the 802.11 work. FullMAC chips fit badly into that shape, which is one reason Broadcom’s brcmfmac, the textbook FullMAC driver, has been a sore spot for us for years. Intel’s newer chips go through iwlwifi(4), which leans harder on firmware with every generation and comes to us from Linux. More on that below.

GPUs went down the same road. Since Turing, every NVIDIA card carries a RISC-V coprocessor called the GSP, the GPU System Processor, and NVIDIA’s open kernel modules hand initialization and power management to firmware running on it. Nouveau on Linux added GSP support in 6.7 and cannot drive RTX 40 cards without it. As of 6.18 it is also the default on Turing and Ampere. On FreeBSD, NVIDIA means the binary driver NVIDIA builds for us, so we never had a nouveau to argue about. AMD lands on us all the same: before amdgpu draws a single pixel, you install gpu-firmware-kmod so it can feed blobs to the collection of small processors living on the card.

So the modern “driver” for a GPU or a WiFi card is mostly an RPC client. It marshals requests and waits for another computer across the bus to answer. This is a distributed system. We just do not call it one, so we do not design it like one.

I recognized the pattern because I have watched it in web development for years. A FullMAC driver is an API wrapper. It takes a request from the kernel, reshapes it, and forwards it to someone else’s server, which happens to live on the same card. Nothing is wrong with a wrapper, if you design it as one. Most drivers never were.

Web people built a whole economy on that move. Half the SaaS products launched in the last few years are a wrapper that forwards your query to another SaaS and hands back the answer with a logo on it. Then they raise $10 million to maintain the infrastructure, which turns out to be a single Kubernetes YAML file wrapped around a few AWS Lambda or Vercel functions. A Jenga tower with a pitch deck.

At least the driver developers do not ask for a Series A.

Both worlds share the same weakness: the protocol between the computers is not stable. When the upstream SaaS changes its API or its pricing, the wrapper dies overnight. When nouveau gained GSP support, it worked with the firmware from one specific NVIDIA driver series, R535, because the firmware has no stable ABI. The driver and the blob are welded together by version number. It is a new block in the tower, and the worst kind: one you cannot read.

flowchart TB
    subgraph then["Then: host drives the hardware"]
        A1[Kernel driver] -->|registers| B1[Dumb device]
    end
    subgraph now["Now: host talks to another computer"]
        A2[Kernel driver] -->|RPC over PCIe| B2[Firmware on a RISC-V core]
        B2 -->|registers| C2[Actual hardware]
    end

One Chip, Two Drivers

Early laptops had WiFi on one card and Bluetooth on another, sometimes from different vendors. That made sense. They were different radios with nothing to share.

Today they share a die. On an Intel AX200 or AX210, WiFi and Bluetooth sit on one chip and share its antennas, often on 2.4 GHz. And the operating system still sees two unrelated devices: WiFi arrives over PCIe, Bluetooth over an internal USB connection on the same M.2 card. Each half gets its own bus and driver stack, maintained by people who rarely talk to each other in the kernel tree.

On FreeBSD 16 the split is wider than on most systems. The WiFi half of an AX200 is driven by iwlwifi(4), a Linux driver running on top of LinuxKPI and net80211. The Bluetooth half goes through ng_ubt(4) and ng_ubt_intel, part of our Netgraph-based Bluetooth stack, and its firmware gets pushed from userland by iwmbtfw(8) before the radio will say anything. One piece of silicon, driven by code bases from different operating system traditions, sharing nothing in the kernel.

Meanwhile, the two radios have to share airtime, or they step on each other. That arbitration, called coexistence, happens in the chip’s firmware, out of sight. The OS has two drivers that each believe they own a radio, and a third party nobody can see is deciding which one actually gets to transmit.

I first ran into this a few years ago, reading Espressif’s documentation for the ESP32. The chip has one 2.4 GHz radio front end, and WiFi and Bluetooth take turns on it under a coexistence scheduler. Read the WiFi section and then the Bluetooth section, and it feels like watching Pocahontas and then Avatar: same plot, different world. Two protocols have to share the same land, and somebody has to negotiate the peace. Every time, it is a love story set at 2.4 GHz.

flowchart TB
    subgraph os["FreeBSD 16 kernel"]
        W["iwlwifi(4) on LinuxKPI + net80211"]
        B["ng_ubt(4) + ng_ubt_intel on Netgraph"]
    end
    U["iwmbtfw(8) in userland"] -->|loads firmware| B
    subgraph chip["One combo chip"]
        WF[WiFi firmware]
        BF[Bluetooth firmware]
        C{{"Coexistence arbiter"}}
        A(("Shared 2.4 GHz antenna"))
    end
    W -->|PCIe| WF
    B -->|USB| BF
    WF --> C
    BF --> C
    C --> A

This is what the tower looks like at the top: the hardware has already merged, and the software is still pretending it is two cards from 2005 because that is how the driver model was laid out.

The Shims on the Shims

From inside FreeBSD you get to see the tower from the side.

Hardware vendors write Linux drivers. Some of them write Windows drivers. Almost none of them write ours. So we built LinuxKPI, a layer that implements enough of the Linux kernel API for Linux drivers to compile and run in our kernel. That is how drm-kmod gives us amdgpu and i915, and how iwlwifi(4) and the Realtek rtw88/rtw89 drivers give us modern WiFi. It works, and the people who maintain it do heroic work, chasing a Linux internal API that promises nobody stability.

But look at the stack: a FreeBSD kernel, emulating Linux kernel interfaces, running a Linux driver, which talks to a firmware blob, which runs on a coprocessor, which drives the actual silicon. Each layer exists because the layer above could not afford to change.

flowchart TB
    K[FreeBSD kernel] --> L["LinuxKPI: Linux kernel API emulation"]
    L --> D["Linux driver: drm-kmod, iwlwifi"]
    D --> F[Firmware blob]
    F --> P[Coprocessor on the device]
    P --> H[Actual silicon]

As a committer, I want LinuxKPI gone. That is a goal measured in years. Every driver that runs on it today needs a native replacement before the layer can go, and the vendors are not going to write those for us. Until then, the shim stays, and so does the block it props up.

Why Compatibility Stopped Paying

The original deal was reasonable. You pay an emulation tax on every operation, and in exchange you never rewrite your drivers. When a generation of hardware lasted ten years, the tax was amortized over ten years of not rewriting anything.

That deal is broken now. Storage controllers and GPUs turn over every year or two. The compatibility layer never gets amortized, because the hardware it is protecting is already obsolete by the time anyone has optimized the shim. We pay the full tax on devices that have nothing left to emulate.

The irony is that we already have the tools to move fast: kernels ship every few months and firmware updates over the air. The reason we stack blocks is habit from a slower era.

What Rethinking Looks Like

I do not have a finished design for everything, but I have more than a direction.

Stop lying about the media. If the device is flash, expose it as flash. ZNS and FDP prove it works at scale. The filesystem already knows which data is hot and which is cold. Let it tell the drive, instead of making the drive guess.

Treat firmware as a peer. If half the driver lives on a coprocessor, then the interface between them is a network protocol and deserves to be treated like one: versioned and negotiated at startup. A driver that only works with one blob version is a cable soldered to one specific socket.

Model devices as they are built. A combo chip is one device with two radios. Give it one driver with a shared view of the airtime, or at least a documented coexistence interface the OS can participate in.

Build the framework before the driver. Anything that processes frames needs a framework underneath it, whether the frames are video or 802.11. Without one, every driver reinvents the same plumbing, and every reinvention is another block.

What I Am Building

That last point is not theory. I did it once already with video(4), the video capture framework that lands in FreeBSD 16. Hardware drivers plug into it and never touch an ioctl: the framework owns the device nodes and the buffer management. Two drivers inherit from it today, uvideo(4) for USB webcams and fwcam(4) for FireWire cameras, and a third is on the way once I finish fixing it. I told that story in Pencils Down Since 1954.

It speaks V4L2 to userland, the Linux video API, because that is what every application already uses. This is the right place for compatibility: one stable interface at the edge, with a clean framework behind it and no shim stacked on a shim.

Now I am doing the same for wireless. It is a new set of drivers for FreeBSD on a new architecture, written from scratch. Where I needed to know how the hardware behaves, I reverse-engineered the behavior. The code itself is built on state machines, and none of it is the vendor’s code. The wireless framework is done and in testing.

The code is semi-closed until it matures. I will open it when it is ready. Until then I do not want someone desperate for attention to point an agent loop at a half-finished tree and post the result to Hacker News as their breakthrough.

Semi-closed still has a door. I add people who can show they are BSD veterans and who have no plans to write an article about how some model or agent harness one-shotted it.

None of this is free. Somebody has to break something to get there. But the alternative is to keep pulling blocks from the bottom and stacking them on top, and everyone who has played Jenga knows how that ends.

The hardware stopped pretending years ago. It is time the drivers and the software did too.

🔗Interstellar Communications

No transmissions detected yet.Be the first to establish contact!

• Link to this post from your site• Share your thoughts via webmention• Join the IndieWeb conversation

Related Posts

SeurOS: The Operating System I Never Wrote

One vain question to ChatGPT became four months, $8,000, and 20,000 commits of an operating system that only loved one ThinkPad. Then came the autopsy: borrowed kernels, erased attribution, and a filesystem I reinvented years after Matthew Dillon shipped HAMMER. From SeurOS to GaslightOS, my Linux phone experiment with voice control and three hours of battery life, this is how I learned that generating code is not authorship, booting is not proof, and the reading is the work.

AIosdevoperating-systems

flashrom 2.0 Will Ask Your Chip for Its Papers

flashrom 1.8.0 shipped three days ago. There won't be a 1.9.0. The next release is 2.0.0, exactly 25 years after the first commit, and it ships with a model that never hallucinates, scores 100% on chip identification, and fits in a PDF.

opensourceflashromfirmware

I Became a flashrom Maintainer. Then I Bought Every SPI Flash Chip I Could Find.

A Bus Pirate bug pointed me at flashrom's Gerrit queue years ago, and I walked away the moment I saw the thread full of corporate email addresses. A coreboot fleet and one uninitialized-variable warning dragged me back in. Now I own a few thousand dollars of unverified SPI flash and a plan to fix that for everyone.

opensourcemaintainer-experiencehardware