Today I pushed a small fix for mtw: the MediaTek MT7601U USB WiFi driver in FreeBSD.
The issue: driver worked perfectly on first boot. Connect the adapter, it initializes, you're online. Great. Then you reboot your machine and... nothing. "timeout waiting for MCU to initialize." The only fix was to physically unplug the adapter and plug it back in, or do a full cold boot (power off completely).
The root cause was a state machine transition problem. When you do a warm reboot, USB devices don't lose power - they just sit there, happily retaining whatever state they were in. The MT7601U's microcontroller still had its "ready" flag set from the previous session. So when the driver came back up and checked "is firmware already running?", the device said "yep!" and the driver said "cool, nothing to do" and returned early.
Except the device wasn't actually ready. It was in a Schrödinger state - simultaneously "ready" and "not ready" until you observe it by trying to actually probe it, at which point the wavefunction collapses into "definitely broken." Technically powered, firmware loaded, flags set, but not actually functional.
The fix was straightforward: if we detect the MCU is already marked ready at attach time, assume it's stale state from a previous session, reset the MCU, clear the ready flag, and do a proper initialization from scratch. Force the cat to be alive.
Also added USB re-enumeration on attach and bumped some timeouts because these devices can be slow after a reset.
What's funny about driver development is that progress isn't linear. You find and fix a bug in hardware revision 1 and 2. Revision 3 ships and works perfectly - they must have fixed it in silicon, you think. Then revision 6 manufactured a year later shows up with the exact same bug. Different fab? Cost reduction? Recycled design from a different product line? Who knows.
You end up maintaining a mental map of "this chip from this date range has this quirk, but the same chip from that date range doesn't, except if it's from this OEM who used a different reference design."
And the datasheets - when they exist - are always for the "ideal" version of the hardware that exists only in the minds of the engineers who wrote them.
Anyway, if you're running FreeBSD with an MT7601U adapter and wondered why you had to unplug it after every reboot, this one's for you.