Skip to contentSkip to conversation

gpu: nova-core: gsp: cmdq: preparatory patches for r000 and vGPU

PATCH Applied Alexandre Courbot 2 participants 6 messages Nov 16 – Nov 20

Subsystems (4)
lore
Share & tools
lore

Alexandre Courbot

author maintainer
#0 lore raw

cover gpu: nova-core: gsp: cmdq: preparatory patches for r000 and vGPU

A couple more command queue patches for the r000 and vGPU work. Patch 1 allows commands to specify a custom timeout, as some commands can take longer than the default 5 seconds on occasion.

Patch 2 adds support for GMC commands that expect a return status, but no returned payload.

Based on drm-rust-next.

---
Alexandre Courbot (2):
gpu: nova-core: gsp: cmdq: let GMC commands set their completion timeout
gpu: nova-core: gsp: cmdq: support GMC replies without payload

 drivers/gpu/nova-core/gsp/cmdq.rs     |  5 +++--
 drivers/gpu/nova-core/gsp/cmdq/gmc.rs | 31 ++++++++++++++++++++++++-------
 drivers/gpu/nova-core/gsp/cmdq/rpc.rs |  2 +-
 3 files changed, 28 insertions(+), 10 deletions(-)

---
base-commit: 8045d0e7d208ad389a387f1407ce0db9070805af
change-id: 20261116-cmdq-timeout-6cf40c6afafc

Best regards,

Signature · 1 line
Alexandre Courbot <[email protected]>
author maintainer
#1 lore raw

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

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.

---
 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(-)
drivers/gpu/nova-core/gsp/cmdq.rs +3 -2
index 8d34acaef9ea..ad37c979d8b7 100644
@@ -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() {
drivers/gpu/nova-core/gsp/cmdq/gmc.rs +9 -5
index 04033c64ca72..512a327a1c89 100644
@@ -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.
drivers/gpu/nova-core/gsp/cmdq/rpc.rs +1 -1
index 10d3f68b2f61..012f3c82e7c5 100644
@@ -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)
     }
 }
Signature · 1 line
2.56.0
Reviewed-by on v1 1/2
#2 lore raw

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

Quoted 9 lines · Alexandre Courbot

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.

Quoted 4 lines

No functional change intended.

---

author maintainer
#3 lore raw

PATCH 2/2 gpu: nova-core: gsp: cmdq: support GMC replies without payload

In reply to Alexandre Courbot

Some GMC commands are answered with a status and no payload. Their reply type cannot be NoReply, which marks commands that the GSP does not answer at all.

Implement MessageFromGsp for () so these commands can use it as their reply type.

---
 drivers/gpu/nova-core/gsp/cmdq/gmc.rs | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/gsp/cmdq/gmc.rs +15 -2
index 512a327a1c89..f4311593e360 100644
@@ -3,6 +3,8 @@
 
 //! Support for the GMC (GPU Management Controller) API message type on the GSP command queue.
 
+use core::convert::Infallible;
+
 use kernel::{
     device,
     prelude::*,
@@ -53,8 +55,8 @@ pub(crate) trait CommandToGsp {
     /// after the GMC API header.
     type Command: FromBytes + AsBytes;
 
-    /// Type of the reply expected from the GSP, or [`NoReply`] for commands that don't have a
-    /// reply.
+    /// Type of the reply expected from the GSP. Can be [`NoReply`] for commands that don't have a
+    /// reply, or `()` for commands that only expect a status code without a reply payload.
     type Reply;
 
     /// Largest reply this command accepts, in bytes. Zero for commands that the GSP does not
@@ -178,6 +180,17 @@ fn read(
     ) -> Result<Self, Self::InitError>;
 }
 
+/// Reply type for commands that the GSP answers with a status and no payload.
+impl MessageFromGsp for () {
+    type InitError = Infallible;
+
+    fn read(
+        _payload: &mut SBufferIter<core::array::IntoIter<&[u8], 2>>,
+    ) -> Result<Self, Self::InitError> {
+        Ok(())
+    }
+}
+
 /// A GMC message ready to be processed from the message queue.
 pub(crate) struct GmcMessage<'a> {
     // Reference to the GMC API header of the message.
Signature · 1 line
2.56.0
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] gpu: nova-core: gsp: cmdq: support GMC replies without payload

Quoted 9 lines · Alexandre Courbot

Some GMC commands are answered with a status and no payload. Their reply type cannot be NoReply, which marks commands that the GSP does not answer at all.

Implement MessageFromGsp for () so these commands can use it as their reply type.

---

author maintainer Applied
#5 lore raw
In reply to Alexandre Courbot
Quoted 8 lines · Alexandre Courbot

A couple more command queue patches for the r000 and vGPU work. Patch 1 allows commands to specify a custom timeout, as some commands can take longer than the default 5 seconds on occasion.

Patch 2 adds support for GMC commands that expect a return status, but no returned payload.

[...]

Applied to drm-rust-next, thanks!

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

      commit: 43041191152d2e8a1371ca28b4f4fcd507f422c2
[2/2] gpu: nova-core: gsp: cmdq: support GMC replies without payload
      commit: 3b63cb016422199f1bda9abdb6503451d3ba9f1e