STRUCT SPI_MEM_OP(9)
π struct spi_mem_op(9) β the Kernel API Manual, but make it make sense β¨
okay bestie, so you know how the kernel talks to SPI memory chips (think flash, like the little storage goblin on your board)? This struct is literally the whole conversation plan π. It's struct spi_mem_op β one (1) complete SPI memory operation, wrapped up in a cute little package: the command, the address, the dummy phase, and the data phase. All four acts of the show, main character energy only π.
It lives in the Kernel API Manual, iykyk π§
πΈ SYNOPSIS πΈ
struct spi_mem_op {
struct {
u8 nbytes;
u8 buswidth;
u8 dtr : 1;
u8 __pad : 7;
u16 opcode;
} cmd;
struct {
u8 nbytes;
u8 buswidth;
u8 dtr : 1;
u8 __pad : 7;
u64 val;
} addr;
struct {
u8 nbytes;
u8 buswidth;
u8 dtr : 1;
u8 __pad : 7;
} dummy;
struct {
u8 buswidth;
u8 dtr : 1;
u8 ecc : 1;
u8 swap16 : 1;
u8 __pad : 5;
enum spi_mem_data_dir dir;
unsigned int nbytes;
union {
void *in;
const void *out;
} buf;
} data;
unsigned int max_freq;
};
like, look at her. four nested structs and a frequency cap. iconic π
π¦ MEMBERS π¦
so let's go through every single one, no skipping, we are NOT leaving anyone out of the group chat π
π the command block
cmdβ the complete command. the whole vibe of "what are we even doing here" π«Άcmd.nbytesβ number of opcode bytes. and listen: only 1 or 2 are valid β οΈ. the opcode is sent MSB-first.cmd.buswidthβ number of IO lines used to transmit the command. how many lanes we're taking, basically π£οΈcmd.dtrβ whether the command opcode should be sent in DTR mode or not. yes/no, that's the whole bit πͺ©cmd.opcodeβ the operation opcode. the actual thing we're asking for, bestie.
π the address block
addrβ the address attributes.addr.nbytesβ number of address bytes to send. can be zero if the operation does not need to send an address. zero is a valid slay πaddr.buswidthβ number of IO lines used to transmit the address cycles.addr.dtrβ whether the address should be sent in DTR mode or not.addr.valβ the address value. this value is always sent MSB first on the bus. and note this note: onlyaddr.nbytesare taken into account in this address value β so users should make sure the value fits in the assigned number of bytes. like, if it doesn't fit, that's on you, not on the struct π
π§ the dummy block
dummyβ data for dummy operation. yes she's called dummy and yes she matters πdummy.nbytesβ number of dummy bytes to send after an opcode or address. can be zero if the operation does not require dummy bytes.dummy.buswidthβ number of IO lanes used to transmit the dummy bytes.dummy.dtrβ whether the dummy bytes should be sent in DTR mode or not.
π the data block
dataβ the data attributes.data.buswidthβ number of IO lanes used to send/receive the data.data.dtrβ whether the data should be sent in DTR mode or not.data.eccβ whether error correction is required or not.data.swap16β whether the byte order of 16-bit words is swapped when read or written in Octal DTR mode compared to STR mode. yes that's the whole sentence, yes it's a lot, yes it's important πΈdata.dirβ direction of the transfer. which way the data's flowing, bestie β‘οΈβ¬ οΈdata.nbytesβ number of data bytes to send/receive. can be zero if the operation does not involve transferring data.data.buf.inβ input buffer (must be DMA-able). must be DMA-able!! say it with me π£data.buf.outβ output buffer (must be DMA-able). also DMA-able, no exceptions π«Ά
β the frequency one
max_freqβ frequency limitation wrt this operation.0means there is no specific constraint and the highest achievable frequency can be attempted. zero = go fast, no cap π₯
π SEE ALSO π
go read these next, they're all in the Kernel file ./include/linux/spi/spi-mem.h:
enum spi_mem_data_dir(9)struct spi_mem_dirmap_info(9)struct spi_mem_dirmap_desc(9)struct spi_mem(9)spi_mem_set_drvdata(9)spi_mem_get_drvdata(9)struct spi_controller_mem_ops(9)struct spi_controller_mem_caps(9)struct spi_mem_driver(9)
like, the whole friend group π
quick vibe check:data.buf.inanddata.buf.outare a union β you get one or the other, not both. and both have to be DMA-able. don't come crying to me if you forget π
that's the page, bestie! π this one came from ./include/linux/spi and it's dated October 2026 β and the struct spi_mem_op(9) girlies stay winning, periodt π
β¨π¦
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms