[PATCH 1/2] gpu: nova-core: gsp: cmdq: let GMC commands set their completion timeout

From: Alexandre Courbot

Date: Mon Nov 16 2026 - 10:07:06 EST


Every wait on the message queue uses `Cmdq::RECEIVE_TIMEOUT`, but some
GMC commands (notably r000's GSP_INIT, and a few vGPU commands) might
take longer to complete.

Make the timeout a parameter of `await_msg_with`, and take it from a new
`CommandToGsp::COMPLETION_TIMEOUT` associated constant when waiting for
the reply to a GMC command. The constant defaults to
`Cmdq::RECEIVE_TIMEOUT`, so existing commands are unaffected.

No functional change intended.

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

diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
index 8d34acaef9ea..ad37c979d8b7 100644
--- a/drivers/gpu/nova-core/gsp/cmdq.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq.rs
@@ -686,7 +686,7 @@ fn consume_element<R>(
/// Consumes messages from the queue until a message that satisfies `f` is encountered, and
/// returns the result of `f`.
///
- /// The message is waited for up to [`Cmdq::RECEIVE_TIMEOUT`] from the call.
+ /// The message is waited for up to `timeout` from the call.
///
/// `f` is expected to return `Ok(Some(_))` with the result to return to the caller, and
/// `Ok(None)` to signal that the received message was not the one expected (such messages are
@@ -700,9 +700,10 @@ fn consume_element<R>(
/// - Any error returned by `f`.
fn await_msg_with<R>(
&mut self,
+ timeout: Delta,
f: impl Fn(GspParsedMessage<'_>) -> Result<Option<R>>,
) -> Result<R> {
- let deadline = Instant::<Monotonic>::now() + Cmdq::RECEIVE_TIMEOUT;
+ let deadline = Instant::<Monotonic>::now() + timeout;
loop {
let remaining = deadline - Instant::<Monotonic>::now();
if remaining.is_negative() {
diff --git a/drivers/gpu/nova-core/gsp/cmdq/gmc.rs b/drivers/gpu/nova-core/gsp/cmdq/gmc.rs
index 04033c64ca72..512a327a1c89 100644
--- a/drivers/gpu/nova-core/gsp/cmdq/gmc.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq/gmc.rs
@@ -6,6 +6,7 @@
use kernel::{
device,
prelude::*,
+ time::Delta,
transmute::{
AsBytes,
FromBytes, //
@@ -61,6 +62,9 @@ pub(crate) trait CommandToGsp {
/// value).
const MAX_REPLY_SIZE: u32;

+ /// Time given to the GSP to complete this command once it is sent.
+ const COMPLETION_TIMEOUT: Delta = Cmdq::RECEIVE_TIMEOUT;
+
/// Error type returned by [`CommandToGsp::init`].
type InitError;

@@ -283,8 +287,8 @@ impl Cmdq<'_> {
///
/// - `EMSGSIZE` if the command does not fit in a single command queue element.
/// - `ETIMEDOUT` if space does not become available to send the command, or if the reply does
- /// not arrive within [`Self::RECEIVE_TIMEOUT`] of the send, however many events arrive
- /// while waiting.
+ /// not arrive within [`CommandToGsp::COMPLETION_TIMEOUT`] of the send, however many events
+ /// arrive while waiting.
/// - `EIO` if the variable payload requested by the command has not been entirely
/// written to by its [`CommandToGsp::init_variable_payload`] method, or if a message fails
/// framing or checksum validation.
@@ -350,7 +354,7 @@ fn send_gmc_command<C>(&mut self, command: C) -> Result<u32>
}

/// Receives the reply of type `C::Reply` to the command sent with sequence number `seq`,
- /// waiting up to [`Cmdq::RECEIVE_TIMEOUT`] from the call.
+ /// waiting up to [`CommandToGsp::COMPLETION_TIMEOUT`] from the call.
///
/// Any GMC event that arrives first is passed to `on_event`, and any RPC message is logged.
/// Neither extends the deadline.
@@ -376,8 +380,7 @@ fn await_gmc_reply<C: CommandToGsp>(
{
let dev = self.dev;

- // TODO: replace `u32` with `NvStatus` once it lands.
- self.await_msg_with(|message| -> Result<Option<Result<C::Reply, u32>>> {
+ self.await_msg_with(C::COMPLETION_TIMEOUT, |message| {
let gmc_message = match message {
GspParsedMessage::Gmc(gmc_message) => gmc_message,
_ => {
@@ -386,6 +389,7 @@ fn await_gmc_reply<C: CommandToGsp>(
}
};

+ // TODO: use `NvStatus` instead of `u32` for status once it lands.
let status = match gmc_message.reply_status(C::COMMAND, seq) {
Some(status) => status,
// Reply to another command, e.g. one that timed out earlier.
diff --git a/drivers/gpu/nova-core/gsp/cmdq/rpc.rs b/drivers/gpu/nova-core/gsp/cmdq/rpc.rs
index 10d3f68b2f61..012f3c82e7c5 100644
--- a/drivers/gpu/nova-core/gsp/cmdq/rpc.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq/rpc.rs
@@ -401,6 +401,6 @@ fn await_rpc_msg<M: MessageFromGsp>(&mut self) -> Result<M>
}
};

- self.await_msg_with(f)
+ self.await_msg_with(Cmdq::RECEIVE_TIMEOUT, f)
}
}

--
2.56.0