SMB(4)
π SMB(4) β the Kernel Interfaces Manual, but make it a group chat
okay so bestie, gather round, because today we're talking about smb β that's the System Management Bus, aka SMBus, and this page is literally the generic I/O device driver manual. It lives in the Kernel Interfaces Manual section (section 4, if you're keeping score π), and I'm gonna walk you through every single bit of it. no skips. no cap.
β¨ NAME β¨
smb β the System Management Bus (SMBus) generic I/O device driver π¦
β¨ SYNOPSIS β¨
device smb
that's it. that's the whole vibe. a single line. iconic. π
β¨ DESCRIPTION β¨
so the smb character device driver is basically the plug that gives you generic I/O to any smbus(4) instance π think of it as the middleman that's like "yeah I got you" between you and your SMB devices.
To actually control SMB devices, you use /dev/smb? together with the ioctls described down below β¨. And heads up: any of these ioctl commands takes a pointer to struct smbcmd as its argument. one struct to rule them all, periodt.
#include <sys/types.h>
struct smbcmd {
u_char cmd;
u_char reserved;
u_short op;
union {
char byte;
char buf[2];
short word;
} wdata;
union {
char byte;
char buf[2];
short word;
} rdata;
int slave;
char *wbuf; /* use wdata if NULL */
int wcount;
char *rbuf; /* use rdata if NULL */
int rcount;
};
look at that struct. gorgeous. no notes. π§
πΈ the slave field
The slave field is always used, and it gives you the address of the SMBus slave device π«Ά. Now, the tea: the slave address lives in the seven most significant bits β that is, it's βleft-justifiedβ β and the least significant bit of the slave address must be zero β. don't try to sneak a 1 in that LSB, bestie, the driver is not playing games π.
π the ioctl menu (the whole menu, not just the specials)
SMB_QUICK_WRITEβ QuickWrite is out here transferring zero data π. It literally just issues the device address with write intent onto the bus. that's the whole job. she came, she addressed, she left.SMB_QUICK_READβ QuickRead also transfers no data. It just issues the device address with read intent to the bus. same energy, read edition π₯SMB_SENDBβ SendByte sends the byte provided incmdto the device. simple. clean. slay πSMB_RECVBβ ReceiveByte reads a single byte from the device, and that byte comes back incmd. oh we're getting something back, love that for us πSMB_WRITEBβ WriteByte first sends the byte fromcmdto the device, followed by the byte given inwdata.byte. two bytes in a trench coat π§₯SMB_WRITEWβ WriteWord first sends the byte fromcmdto the device, followed by the word given inwdata.word. and ngl, important note: the SMBus byte-order is little-endian by definition π so don't come crying to me about endianness, it's literally in the spec.SMB_READBβ ReadByte first sends the byte fromcmdto the device, then reads one byte of data from the device. Returned data is stored inrdata.byte. cute little round trip πSMB_READWβ ReadWord first sends the byte fromcmdto the device, then reads one word of data from the device. Returned data goes inrdata.word. big girl read π₯SMB_PCALLβ ProcedureCall first sends the byte fromcmdto the device, followed by the word provided inwdata.word. It then reads one word of data from the device and returns it inrdata.word. a whole conversation, honestly π¬SMB_BWRITEβ BlockWrite first sends the byte fromcmdto the device, then the byte fromwcount, followed bywcountbytes of data taken from the buffer pointed to bywbuf. β οΈ And the SMBus specification mandates that no more than 32 bytes of data can be transferred in a single block read or write command β and you can read that value from the constantSMB_MAXBLOCKSIZE. do not exceed the 32. I'm serious. the spec said so π¨SMB_BREADβ BlockRead first sends the byte fromcmdto the device, then reads a count of data bytes that the device is going to provide, and then reads that many bytes. The count is returned inrcount, and the data comes back in the buffer pointed to byrbuf. the full unboxing experience π¦β¨
π«Ά one more thing, and it matters: theread(2)andwrite(2)system calls are not implemented by this driver. so don't call them. they will not answer. it's giving left-on-read π
π ERRORS π
The ioctl(2) commands can cause the following driver-specific errors β learn them, love them, recognize them in the wild:
[ENXIO]β Device did not respond to selection. she ghosted you π₯²[EBUSY]β Device still in use. someone else has the aux cord π[ENODEV]β Operation not supported by device (not supposed to happen). so if you see this... π (it's literally noted as not supposed to happen, so, y'know.)[EINVAL]β General argument error. you passed something cursed, bestie π[EWOULDBLOCK]β SMBus transaction timed out. the bus took too long, we're moving on β°
π SEE ALSO π
go read those too, I'm not gonna gatekeep π
π¦ HISTORY π¦
The smb manual page first appeared in FreeBSD 3.0. a whole era. vintage. antique even π
π AUTHORS π
This manual page was written by Nicolas Souchu and extended by Michael Gmelin <freebsd@grem.de> π«Ά absolute legends, both of them. credit where credit is due, always.
and that's the whole page, bestie β go forth and talk to your SMBus devices responsibly πΈπβ¨
this edition of the page came from the Debian packaging, dated April 25, 2015 β so if you're reading this in the future, yes, she's a classic π ily, bye π
π¦ where this page comes from
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 1998, Nicolas Souchu
- Copyright (c) 2004, Joerg Wunsch
- Copyright (c) 2015, Michael Gmelin <freebsd@grem.de>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms