[PATCH v2 5/5] gpu: nova-core: gsp: cmdq: expose the sequence number of sent commands

From: Alexandre Courbot

Date: Mon Nov 02 2026 - 07:18:36 EST


The r000 firmware requires matching the sequence number of sent commands
with the responses received from the GSP. Make `send_command_element`
return the sequence number to that end, and ignore it for now.

No functional change intended.

Signed-off-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
---
drivers/gpu/nova-core/gsp/cmdq.rs | 11 +++++++----
drivers/gpu/nova-core/gsp/cmdq/rpc.rs | 4 +++-
2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
index 33cb9174c1e6..65f25d3c4d98 100644
--- a/drivers/gpu/nova-core/gsp/cmdq.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq.rs
@@ -524,27 +524,30 @@ impl CmdqInner<'_> {
/// Allocate enough space on the command queue to store `command`, initialize it with
/// [`CommandElement::write`], and send the command to the GSP.
///
+ /// Returns the sequence number of the sent element.
+ ///
/// # Errors
///
/// - `EMSGSIZE` if the command exceeds the maximum queue element size.
/// - `ETIMEDOUT` if space does not become available within the timeout.
///
/// Error codes returned by [`CommandElement::write`] are returned as-is.
- fn send_command_element<E: CommandElement>(&mut self, command: E) -> Result {
+ fn send_command_element<E: CommandElement>(&mut self, command: E) -> Result<u32> {
let size_in_bytes = command.size();
+ let seq = self.seq;
let mut dst = self
.gsp_mem
.allocate_command(size_in_bytes, Self::ALLOCATE_TIMEOUT)?;

// Fill the header.
- let msg_element_init = GspMsgElement::init(self.seq, size_in_bytes);
+ let msg_element_init = GspMsgElement::init(seq, size_in_bytes);
// SAFETY: `dst.header` is a valid reference, and is not touched if the initializer fails.
unsafe {
pin_init::raw_try_init(core::ptr::from_mut(dst.header), msg_element_init)?;
}

// Write the message payload.
- command.write(self.dev, self.seq, &mut dst)?;
+ command.write(self.dev, seq, &mut dst)?;

// Compute checksum now that the whole message is ready.
dst.header
@@ -559,7 +562,7 @@ fn send_command_element<E: CommandElement>(&mut self, command: E) -> Result {
self.seq += 1;
self.gsp_mem.advance_cpu_write_ptr(elem_count);

- Ok(())
+ Ok(seq)
}

/// Wait for a message to become available on the message queue.
diff --git a/drivers/gpu/nova-core/gsp/cmdq/rpc.rs b/drivers/gpu/nova-core/gsp/cmdq/rpc.rs
index 2c52ec78871b..36cba7c28d3e 100644
--- a/drivers/gpu/nova-core/gsp/cmdq/rpc.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq/rpc.rs
@@ -354,7 +354,9 @@ fn send_rpc_command<M>(&mut self, command: M) -> Result
Error: From<M::InitError>,
{
match SplitState::new(command)? {
- SplitState::Single(command) => self.send_command_element(RpcCommandElement(command)),
+ SplitState::Single(command) => self
+ .send_command_element(RpcCommandElement(command))
+ .map(|_| ()),
SplitState::Split(command, mut continuations) => {
self.send_command_element(RpcCommandElement(command))?;


--
2.56.0