STRUCT SPI_MESSAGE(9)
π¦ struct spi_message(9) β like, the whole vibe π¦
okay bestie, welcome to the struct spi_message(9) page from the Kernel API Manual β yes that's the manual name, we're in kernel API territory, put your big-girl hat on π
β¨ NAME β¨
struct spi_message β one multi-segment SPI transaction, aka the whole group-chat of transfers that has to go out together, no cap π
π SYNOPSIS π
struct spi_message {
struct list_head transfers;
struct spi_device *spi;
bool pre_optimized;
bool optimized;
bool prepared;
int status;
void (*complete)(void *context);
void *context;
unsigned frame_length;
unsigned actual_length;
struct list_head queue;
void *state;
void *opt_state;
struct spi_offload *offload;
struct list_head resources;
};
π Members π
girl, let's meet the cast, one field at a time π«Ά
transfersβ the list of transfer segments in this transaction. it's the roster. the lineup. the main characters β¨spiβ the SPI device this transaction gets queued to πpre_optimizedβ abool; the peripheral driver pre-optimized the messageoptimizedβ abool; the message is in the optimized statepreparedβ abool;spi_prepare_messagewas called for the this message (yes, "the this" β that's the original wording, i don't make the rules π)statusβ zero for success, else negativeerrno. iconic little pass/fail meter πcompleteβ called to report transaction completions. it's the "we're done here" callback π¬contextβ the argument tocompletewhen it's calledframe_lengthβ the total number of bytes in the messageactual_lengthβ the total number of bytes that were transferred in all successful segments. emphasis on successful, bestie πΈqueueβ for use by whichever driver currently owns the messagestateβ for use by whichever driver currently owns the messageopt_stateβ for use by whichever driver currently owns the messageoffloadβ (optional) offload instance used by this message π₯resourcesβ for resource management when the SPI message is processed
yeahqueue,stateandopt_stateall have the exact same description. that's not me being lazy, that's the API. three separate little scratchpads for whoever owns the message π§
πΈ Description πΈ
so a spi_message is used to execute an atomic sequence of data transfers, and each one of those transfers is represented by a struct spi_transfer β¨
the sequence is "atomic" in the sense that no other spi_message may use that SPI bus until that sequence completes β like, the bus is busy, do not perceive her π
on some systems, many such sequences can execute as a single programmed DMA transfer. highkey efficient π₯
on all systems, these messages are queued, and might complete after transactions to other devices. so like, don't hold your breath waiting, she'll get there when she gets there π
messages sent to a given spi_device are always executed in FIFO order β first in, first out, no cutting the line, periodt β
the code that submits an spi_message (and its spi_transfers) to the lower layers is responsible for managing its memory π«Ά
zero-initialize every field you don't set up explicitly, to insulate against future API updates. this one matters, bestie β it's literally future-proofing yourself π
after you submit a message and its transfers, ignore them until its completion callback. like, leave them on read. don't touch. do not go poking at memory that isn't yours yet π
π¦ SEE ALSO π¦
- Kernel file
./include/linux/spi/spi.h struct spi_statistics(9)struct spi_delay(9)struct spi_device(9)struct spi_driver(9)spi_unregister_driver(9)module_spi_driver(9)struct spi_controller(9)struct spi_res(9)struct spi_transfer(9)spi_message_init_with_transfers(9)spi_is_bpw_supported(9)spi_bpw_to_bytes(9)spi_controller_xfer_timeout(9)struct spi_replaced_transfers(9)spi_sync_transfer(9)spi_write(9)spi_read(9)spi_w8r8(9)spi_w8r16(9)spi_w8r16be(9)struct spi_board_info(9)
and that's the page, bestie π this whole thing came out of ./include/linux/spi and it's the October 2026 edition β so like, slay, go forth and queue your messages in FIFO order πβ¨
π¦ 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