From: Zhi Wang <zhiw@nvidia.com>
To: <dakr@kernel.org>, <acourbot@nvidia.com>
Cc: <alex@shazbot.org>, <jgg@nvidia.com>, <yishaih@nvidia.com>,
<skolothumtho@nvidia.com>, <kevin.tian@intel.com>,
<airlied@gmail.com>, <simona@ffwll.ch>, <ojeda@kernel.org>,
<alex.gaynor@gmail.com>, <boqun.feng@gmail.com>,
<gary@garyguo.net>, <bjorn3_gh@protonmail.com>,
<lossin@kernel.org>, <a.hindborg@kernel.org>,
<aliceryhl@google.com>, <tmgross@umich.edu>,
<jhubbard@nvidia.com>, <ecourtney@nvidia.com>, <cjia@nvidia.com>,
<smitra@nvidia.com>, <kjaju@nvidia.com>, <alkumar@nvidia.com>,
<ankita@nvidia.com>, <aniketa@nvidia.com>, <kwankhede@nvidia.com>,
<targupta@nvidia.com>, <nova-gpu@lists.linux.dev>,
<linux-kernel@vger.kernel.org>, <zhiwang@kernel.org>,
Zhi Wang <zhiw@nvidia.com>
Subject: [PATCH v3 17/31] gpu: nova-core: vgpu: query VF assignments and properties
Date: Mon, 28 Sep 2026 13:28:20 +0300 [thread overview]
Message-ID: <0141df169a72e603ea1df4f94916edd55c6cb6d4.1790580105.git.zhiw@nvidia.com> (raw)
In-Reply-To: <cover.1790580105.git.zhiw@nvidia.com>
Creating an instance requires its VF assignment and the corresponding
vGPU properties before reserving resources.
Call Cmdq's synchronous GMC interface with each query's command ID,
request payload and receive capacity. Check the matching reply's
firmware status before decoding it, and report the command and raw
NV_STATUS when firmware rejects the request.
Decode the VF assignment and NVKV property replies at their query entry
points. Validate the returned type ID and nonzero instance limit, and
initialize the decoded properties on the heap. Keep the raw queue
interface available to firmware-control clients.
Co-developed-by: Eliot Courtney <ecourtney@nvidia.com>
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
Signed-off-by: Zhi Wang <zhiw@nvidia.com>
---
drivers/gpu/nova-core/gsp.rs | 1 +
drivers/gpu/nova-core/gsp/cmdq.rs | 3 -
drivers/gpu/nova-core/gsp/fw.rs | 2 +-
drivers/gpu/nova-core/vgpu.rs | 2 +
drivers/gpu/nova-core/vgpu/commands.rs | 91 ++++++++++++++++++++++
drivers/gpu/nova-core/vgpu/fw.rs | 17 ++++
drivers/gpu/nova-core/vgpu/fw/commands.rs | 95 +++++++++++++++++++++++
7 files changed, 207 insertions(+), 4 deletions(-)
create mode 100644 drivers/gpu/nova-core/vgpu/commands.rs
create mode 100644 drivers/gpu/nova-core/vgpu/fw.rs
create mode 100644 drivers/gpu/nova-core/vgpu/fw/commands.rs
diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs
index 25b4bf6eb848..45645bc7c9d8 100644
--- a/drivers/gpu/nova-core/gsp.rs
+++ b/drivers/gpu/nova-core/gsp.rs
@@ -32,6 +32,7 @@
mod regs;
pub(crate) use fw::{
+ r000_00 as bindings,
GspFmcBootParams,
GspFwWprMeta,
LibosMemoryRegionInitArgument,
diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
index 43038c7fe823..abd9edadff64 100644
--- a/drivers/gpu/nova-core/gsp/cmdq.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq.rs
@@ -551,10 +551,8 @@ fn payload_length(&self) -> Option<usize> {
/// Response from a GMC API command.
pub(crate) struct GmcResponse {
/// Response status (`NV_STATUS` code). Zero means success.
- #[expect(dead_code)]
pub(crate) status: u32,
/// Response payload copied out of the message queue.
- #[expect(dead_code)]
pub(crate) payload: KVec<u8>,
}
@@ -708,7 +706,6 @@ pub(crate) fn send_gmc_no_wait(
/// # Errors
///
/// Returns the same errors as [`Self::send_gmc_and_receive_timeout`].
- #[expect(dead_code)]
pub(crate) fn send_gmc_and_receive(
&self,
command_id: u32,
diff --git a/drivers/gpu/nova-core/gsp/fw.rs b/drivers/gpu/nova-core/gsp/fw.rs
index a416826737bb..aef283dda087 100644
--- a/drivers/gpu/nova-core/gsp/fw.rs
+++ b/drivers/gpu/nova-core/gsp/fw.rs
@@ -2,7 +2,7 @@
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
pub(crate) mod commands;
-mod r000_00;
+pub(crate) mod r000_00;
// Alias to avoid repeating the version number with every use.
use r000_00 as bindings;
diff --git a/drivers/gpu/nova-core/vgpu.rs b/drivers/gpu/nova-core/vgpu.rs
index 1402e37541b7..d910445dd2b0 100644
--- a/drivers/gpu/nova-core/vgpu.rs
+++ b/drivers/gpu/nova-core/vgpu.rs
@@ -20,6 +20,8 @@
gsp::commands::FifoEngineList, //
};
+mod commands;
+mod fw;
mod hal;
mod vram;
diff --git a/drivers/gpu/nova-core/vgpu/commands.rs b/drivers/gpu/nova-core/vgpu/commands.rs
new file mode 100644
index 000000000000..679c22b0381a
--- /dev/null
+++ b/drivers/gpu/nova-core/vgpu/commands.rs
@@ -0,0 +1,91 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+//! vGPU firmware command operations.
+//!
+//! Sends requests, checks responses and coordinates the firmware command
+//! sequences used by instance lifecycle operations.
+
+use kernel::{
+ device,
+ prelude::*, //
+};
+
+use crate::gsp::{
+ cmdq::Cmdq,
+ nvkv::{
+ nvkv_words,
+ Decoder,
+ UnknownKeyPolicy, //
+ }, //
+};
+
+use super::{
+ fw::{
+ commands::{
+ VgpuPropertiesSchema, //
+ },
+ GMCAPI_CMD_QUERY_ASSIGNED_VF_VGPU_TYPE,
+ GMCAPI_CMD_QUERY_VGPU_PROPERTIES, //
+ }, //
+};
+
+pub(super) use super::fw::commands::{
+ Dbdf,
+ VgpuProperties, //
+};
+
+/// Reports a matching command's raw firmware status before translating rejection to `EIO`.
+fn check_status(dev: &device::Device<device::Bound>, command_id: u32, status: u32) -> Result {
+ if status == 0 {
+ Ok(())
+ } else {
+ dev_err!(
+ dev,
+ "GMC command {:#x} rejected: NV_STATUS={:#x}\n",
+ command_id,
+ status,
+ );
+ Err(EIO)
+ }
+}
+
+/// Query the vGPU type assigned to a VF by its DBDF.
+#[expect(dead_code)]
+pub(super) fn query_assigned_vf_type(
+ dev: &device::Device<device::Bound>,
+ cmdq: &Cmdq<'_>,
+ dbdf: Dbdf,
+) -> Result<u32> {
+ let command_id = GMCAPI_CMD_QUERY_ASSIGNED_VF_VGPU_TYPE;
+ let payload = u64::from(dbdf.into_raw()).to_le_bytes();
+ // Preserve the firmware receive budget; only the leading type ID is consumed.
+ let response = cmdq.send_gmc_and_receive(command_id, &payload, 64)?;
+ check_status(dev, command_id, response.status)?;
+
+ let bytes = response.payload.first_chunk::<4>().ok_or(ENODEV)?;
+ Ok(u32::from_le_bytes(*bytes))
+}
+
+/// Query and decode the firmware properties of one vGPU type.
+#[expect(dead_code)]
+pub(super) fn query_vgpu_properties(
+ dev: &device::Device<device::Bound>,
+ cmdq: &Cmdq<'_>,
+ type_id: u32,
+) -> Result<KBox<VgpuProperties>> {
+ let command_id = GMCAPI_CMD_QUERY_VGPU_PROPERTIES;
+ // NVKV replies vary in length. This is a receive capacity, not their encoded size.
+ let response = cmdq.send_gmc_and_receive(command_id, &type_id.to_le_bytes(), 4096)?;
+ check_status(dev, command_id, response.status)?;
+
+ let words = nvkv_words(&response.payload, &[])?;
+ let decoder = Decoder::new(&words, UnknownKeyPolicy::Ignore);
+ let mut schema = VgpuPropertiesSchema::default();
+ let properties = KBox::try_init(decoder.decode(&mut schema)?, GFP_KERNEL)?;
+ if properties.type_id != type_id || properties.max_instance == 0 {
+ Err(EINVAL)
+ } else {
+ Ok(properties)
+ }
+}
diff --git a/drivers/gpu/nova-core/vgpu/fw.rs b/drivers/gpu/nova-core/vgpu/fw.rs
new file mode 100644
index 000000000000..23097cb13121
--- /dev/null
+++ b/drivers/gpu/nova-core/vgpu/fw.rs
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+//! vGPU firmware interface.
+//!
+//! Exposes command constants and communication buffer layout types from
+//! raw firmware bindings.
+
+pub(super) mod commands;
+
+use crate::gsp::bindings;
+
+pub(super) const GMCAPI_CMD_QUERY_ASSIGNED_VF_VGPU_TYPE: u32 =
+ bindings::GMCAPI_COMMANDS_GMCAPI_CMD_QUERY_ASSIGNED_VF_VGPU_TYPE;
+
+pub(super) const GMCAPI_CMD_QUERY_VGPU_PROPERTIES: u32 =
+ bindings::GMCAPI_COMMANDS_GMCAPI_CMD_QUERY_VGPU_PROPERTIES;
diff --git a/drivers/gpu/nova-core/vgpu/fw/commands.rs b/drivers/gpu/nova-core/vgpu/fw/commands.rs
new file mode 100644
index 000000000000..a4d23eae8233
--- /dev/null
+++ b/drivers/gpu/nova-core/vgpu/fw/commands.rs
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+//! Wire types and codecs for vGPU commands.
+//!
+//! Defines request encoders and response schemas independently of command
+//! submission and instance lifecycle operations.
+
+use kernel::{
+ alloc::ArrayVec,
+ bitfield, //
+};
+
+use crate::{
+ gsp::nvkv::{
+ nvkv_decode,
+ Array,
+ Key,
+ KeyId,
+ Required, //
+ }, //
+};
+
+bitfield! {
+ pub(crate) struct Dbdf(u32) {
+ 2:0 function;
+ 7:3 device;
+ 15:8 bus;
+ 31:16 domain;
+ }
+}
+
+nvkv_decode! {
+ pub(crate) struct VgpuPropertiesSchema => VgpuProperties {
+ // TODO: `name`/`class` required?
+ name: Array<u8, { VgpuProperties::STRING_LEN }, { Self::TYPE_NAME_KEY }>,
+ class: Array<u8, { VgpuProperties::STRING_LEN }, { Self::CLASS_KEY }>,
+ type_id: Required<u32, { Self::TYPE_ID_KEY }>,
+ bar1_length: Required<u64, { Self::BAR1_LENGTH_KEY }>,
+ max_instance: Required<u32, { Self::MAX_INSTANCE_KEY }>,
+ ecc: Key<u32, { Self::ECC_KEY }>,
+ profile_size: Required<u64, { Self::PROFILE_SIZE_KEY }>,
+ max_fps: Key<u32, { Self::MAX_FPS_KEY }>,
+ num_heads: Key<u32, { Self::NUM_HEADS_KEY }>,
+ max_res_x: Key<u32, { Self::MAX_RES_X_KEY }>,
+ max_res_y: Key<u32, { Self::MAX_RES_Y_KEY }>,
+ dev_id: Required<u32, { Self::DEV_ID_KEY }>,
+ subsystem_id: Required<u32, { Self::SUBSYSTEM_ID_KEY }>,
+ fb_length: Required<u64, { Self::FB_LENGTH_KEY }>,
+ gsp_heap_size: Required<u64, { Self::GSP_HEAP_SIZE_KEY }>,
+ fb_reservation: Required<u64, { Self::FB_RESERVATION_KEY }>,
+ }
+}
+
+impl VgpuPropertiesSchema {
+ const TYPE_NAME_KEY: KeyId = 0x3100;
+ const CLASS_KEY: KeyId = 0x3101;
+ const TYPE_ID_KEY: KeyId = 0x3102;
+ const BAR1_LENGTH_KEY: KeyId = 0x3103;
+ const MAX_INSTANCE_KEY: KeyId = 0x3104;
+ const ECC_KEY: KeyId = 0x3105;
+ const PROFILE_SIZE_KEY: KeyId = 0x3106;
+ const MAX_FPS_KEY: KeyId = 0x3107;
+ const NUM_HEADS_KEY: KeyId = 0x3108;
+ const MAX_RES_X_KEY: KeyId = 0x3109;
+ const MAX_RES_Y_KEY: KeyId = 0x310A;
+ const DEV_ID_KEY: KeyId = 0x310B;
+ const SUBSYSTEM_ID_KEY: KeyId = 0x310C;
+ const FB_LENGTH_KEY: KeyId = 0x310D;
+ const GSP_HEAP_SIZE_KEY: KeyId = 0x310E;
+ const FB_RESERVATION_KEY: KeyId = 0x310F;
+}
+
+pub(crate) struct VgpuProperties {
+ name: ArrayVec<u8, { Self::STRING_LEN }>,
+ class: ArrayVec<u8, { Self::STRING_LEN }>,
+ pub(crate) type_id: u32,
+ pub(crate) bar1_length: u64,
+ pub(crate) max_instance: u32,
+ ecc: u32,
+ profile_size: u64,
+ max_fps: u32,
+ num_heads: u32,
+ max_res_x: u32,
+ max_res_y: u32,
+ pub(crate) dev_id: u32,
+ pub(crate) subsystem_id: u32,
+ pub(crate) fb_length: u64,
+ pub(crate) gsp_heap_size: u64,
+ fb_reservation: u64,
+}
+
+impl VgpuProperties {
+ const STRING_LEN: usize = 64;
+}
next prev parent reply other threads:[~2026-09-28 10:31 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 10:28 [PATCH v3 00/31] Introduce NVIDIA vGPU manager Zhi Wang
2026-09-28 10:28 ` [PATCH v3 01/31] gpu: nova-core: gsp: pass boot context through setup helpers Zhi Wang
2026-09-28 10:28 ` [PATCH v3 02/31] gpu: nova-core: gsp: decouple boot context from VgpuManager Zhi Wang
2026-09-28 10:28 ` [PATCH v3 03/31] gpu: nova-core: vgpu: detect boot state independently Zhi Wang
2026-09-28 10:28 ` [PATCH v3 04/31] gpu: nova-core: gpu: add a channel ID pool for vGPU Zhi Wang
2026-09-28 10:28 ` [PATCH v3 05/31] gpu: nova-core: gsp: decode the FIFO engine table Zhi Wang
2026-09-28 10:28 ` [PATCH v3 06/31] gpu: nova-core: vgpu: initialize runtime parameters after GSP boot Zhi Wang
2026-09-28 10:28 ` [PATCH v3 07/31] gpu: nova-core: vgpu: reserve the 48-VM WPR2 heap Zhi Wang
2026-10-01 21:11 ` Timur Tabi
2026-09-28 10:28 ` [PATCH v3 08/31] gpu: nova-core: mm: borrow BarUser for temporary BAR1 access Zhi Wang
2026-09-28 10:28 ` [PATCH v3 09/31] gpu: nova-core: mm: add VramBlock Zhi Wang
2026-09-28 10:28 ` [PATCH v3 10/31] gpu: nova-core: mm: add VramRegion Zhi Wang
2026-09-28 10:28 ` [PATCH v3 11/31] gpu: nova-core: mm: add BarMapping Zhi Wang
2026-09-28 10:28 ` [PATCH v3 12/31] gpu: nova-core: gsp: add synchronous GMC transactions Zhi Wang
2026-09-28 10:28 ` [PATCH v3 13/31] gpu: nova-core: gsp: wait for GMC completion events Zhi Wang
2026-09-28 10:28 ` [PATCH v3 14/31] gpu: nova-core: vgpu: add r000 plugin bindings Zhi Wang
2026-09-28 10:28 ` [PATCH v3 15/31] gpu: nova-core: vgpu: add VRAM slot allocator Zhi Wang
2026-09-28 10:28 ` [PATCH v3 16/31] gpu: nova-core: gsp: factor out NVKV payload conversion Zhi Wang
2026-09-28 10:28 ` Zhi Wang [this message]
2026-09-28 10:28 ` [PATCH v3 18/31] gpu: nova-core: vgpu: add instance create/destroy Zhi Wang
2026-09-28 10:28 ` [PATCH v3 19/31] gpu: nova-core: vgpu: encode vGPU boot requests Zhi Wang
2026-09-28 10:28 ` [PATCH v3 20/31] gpu: nova-core: vgpu: add GSP plugin communication buffers Zhi Wang
2026-09-28 10:28 ` [PATCH v3 21/31] gpu: nova-core: vgpu: add instance boot Zhi Wang
2026-09-28 10:28 ` [PATCH v3 22/31] gpu: nova-core: vgpu: add instance shutdown Zhi Wang
2026-09-28 10:28 ` [PATCH v3 23/31] gpu: nova-core: vgpu: initialize GSP plugin RPC buffers Zhi Wang
2026-09-28 10:28 ` [PATCH v3 24/31] gpu: nova-core: vgpu: add GSP plugin RPC transactions Zhi Wang
2026-09-28 10:28 ` [PATCH v3 25/31] gpu: nova-core: vgpu: negotiate the GSP plugin RPC version Zhi Wang
2026-09-28 10:28 ` [PATCH v3 26/31] gpu: nova-core: vgpu: send GSP plugin configuration parameters Zhi Wang
2026-09-28 10:28 ` [PATCH v3 27/31] gpu: nova-core: vgpu: update the GSP plugin BME state Zhi Wang
2026-09-28 10:28 ` [PATCH v3 28/31] gpu: nova-core: vgpu: add CeUtils commands Zhi Wang
2026-09-28 10:28 ` [PATCH v3 29/31] gpu: nova-core: vgpu: scrub guest VRAM with CeUtils Zhi Wang
2026-09-28 10:28 ` [PATCH v3 30/31] gpu: nova-core: vgpu: export plugin log buffers via debugfs Zhi Wang
2026-09-28 10:28 ` [PATCH v3 31/31] gpu: nova-core: vgpu: introduce SR-IOV PF APIs Zhi Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0141df169a72e603ea1df4f94916edd55c6cb6d4.1790580105.git.zhiw@nvidia.com \
--to=zhiw@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=alex@shazbot.org \
--cc=aliceryhl@google.com \
--cc=alkumar@nvidia.com \
--cc=aniketa@nvidia.com \
--cc=ankita@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=cjia@nvidia.com \
--cc=dakr@kernel.org \
--cc=ecourtney@nvidia.com \
--cc=gary@garyguo.net \
--cc=jgg@nvidia.com \
--cc=jhubbard@nvidia.com \
--cc=kevin.tian@intel.com \
--cc=kjaju@nvidia.com \
--cc=kwankhede@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=simona@ffwll.ch \
--cc=skolothumtho@nvidia.com \
--cc=smitra@nvidia.com \
--cc=targupta@nvidia.com \
--cc=tmgross@umich.edu \
--cc=yishaih@nvidia.com \
--cc=zhiwang@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®