Re: [PATCH v6 21/34] gpu: nova-core: vgpu: query VF assignments and properties

From: Danilo Krummrich

Date: Fri Dec 04 2026 - 16:03:28 EST


On Wed Dec 2, 2026 at 9:28 AM CET, Alok Kumar wrote:
> +struct QueryAssignedVfVgpuType(Dbdf);
> +
> +impl CommandToGsp for QueryAssignedVfVgpuType {
> + const COMMAND: GmcCommandId = GmcCommandId::QueryAssignedVfVgpuType;
> + type Command = u64;
> + type Reply = AssignedVfVgpuType;
> + const MAX_REPLY_SIZE: u32 = cv!(size_of::<AssignedVfVgpuType>());
> + type InitError = Infallible;
> +
> + fn init(&self) -> impl Init<Self::Command, Self::InitError> {
> + u64::from(self.0.into_raw()).to_le()
> + }
> +}
> +
> +impl MessageFromGsp for AssignedVfVgpuType {
> + type InitError = Error;
> +
> + fn read(payload: &mut MessagePayload<'_>) -> Result<Self, Self::InitError> {
> + payload.read()
> + }
> +}
> +
> +/// Query the vGPU type assigned to a VF by its DBDF.
> +#[expect(dead_code)]
> +pub(super) fn query_assigned_vf_type(
> + _dev: &device::Device,
> + cmdq: &Cmdq<'_>,
> + dbdf: Dbdf,
> +) -> Result<u32> {
> + let reply = cmdq
> + .send_gmc_command(QueryAssignedVfVgpuType(dbdf), |_| Ok(()))?
> + .map_err(|_| EIO)?;
> +
> + Ok(reply.vgpu_type_id)
> +}
> +
> +struct QueryVgpuProperties(u32);

Please don't use freestanding functions for this, this should instead be

struct QueryAssignedVfVgpuType(Dbdf);

impl QueryAssignedVfVgpuType {
pub(super) fn new(dbdf: Dbdf) -> Self {
Self(dbdf)
}

pub(super) fn send(self, cmdq: &Cmdq<'_>) -> Result<u32> {
let reply = cmdq
.send_gmc_command(QueryAssignedVfVgpuType(dbdf), |_| Ok(()))?
.map_err(|_| EIO)?;

Ok(reply.vgpu_type_id)
}
}

Such that this can be called as

let type_id = QueryAssignedVfVgpuType::new(dbdf).send(cmdq)?;

> +/// Query and decode the firmware properties of one vGPU type.
> +#[expect(dead_code)]
> +pub(super) fn query_vgpu_properties(
> + _dev: &device::Device,
> + cmdq: &Cmdq<'_>,
> + type_id: u32,
> +) -> Result<KBox<VgpuProperties>> {
> + let properties = cmdq
> + .send_gmc_command(QueryVgpuProperties(type_id), |_| Ok(()))?
> + .map_err(|_| EIO)?;
> +
> + if properties.type_id != type_id || properties.max_instance == 0 {
> + Err(EINVAL)
> + } else {
> + Ok(properties)
> + }
> +}

Same here.