SMB(4)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1, nixpkgs unstable

πŸ’… 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 in cmd to the device. simple. clean. slay πŸ’…
  • SMB_RECVB β€” ReceiveByte reads a single byte from the device, and that byte comes back in cmd. oh we're getting something back, love that for us 🎁
  • SMB_WRITEB β€” WriteByte first sends the byte from cmd to the device, followed by the byte given in wdata.byte. two bytes in a trench coat πŸ§₯
  • SMB_WRITEW β€” WriteWord first sends the byte from cmd to the device, followed by the word given in wdata.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 from cmd to the device, then reads one byte of data from the device. Returned data is stored in rdata.byte. cute little round trip 🌈
  • SMB_READW β€” ReadWord first sends the byte from cmd to the device, then reads one word of data from the device. Returned data goes in rdata.word. big girl read πŸ”₯
  • SMB_PCALL β€” ProcedureCall first sends the byte from cmd to the device, followed by the word provided in wdata.word. It then reads one word of data from the device and returns it in rdata.word. a whole conversation, honestly πŸ’¬
  • SMB_BWRITE β€” BlockWrite first sends the byte from cmd to the device, then the byte from wcount, followed by wcount bytes of data taken from the buffer pointed to by wbuf. ⚠️ 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 constant SMB_MAXBLOCKSIZE. do not exceed the 32. I'm serious. the spec said so 🚨
  • SMB_BREAD β€” BlockRead first sends the byte from cmd to 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 in rcount, and the data comes back in the buffer pointed to by rbuf. the full unboxing experience πŸ“¦βœ¨
🫢 one more thing, and it matters: the read(2) and write(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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms