From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.85.63 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796200743; b=bTtYA9glKiUXyLmsqFypf04HZzxxbxZPnCTK7yHtjegir47LcV148RveMZFyl39AXhex czgvIPMMLYmYBUFgsJJ/02F1o/2qRWQcYF1HBXWtwq3IaZruJZ4GvJy1AB/BaFK+wBsF+ UUf21ub5XZ7+02O6PdXszXwU5Rj9LBmLaDyacoemYapqkjSbtFuQhOavqvU+tgZPFbfuW 6Yj7szApQdqkynCUVHYDUOtIPihS2zEpnPwpN//AYf9C0I6HIcyyjTtyYx8dUzIWR3B9H d4xo0yCimjO5Kx3m8si8NeSDjRrqbXPqOSjSnY0UJbNkoyuAGuevYMrOb2NsiIn1New== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796200743; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=WNFSarbeZ6RkMJmMTOIS3ifBMNtrQn7LLVYlJJKl26k=; b=iM5FK0uU1d2cSVckk9cFc4izJ8v9Zbyb3K0waymFOXNnfWlzk4f6QgbMxP6ZEaOvRQVl 0gfL+b24bMdndn7iQeMuPyzgcAnR2+CZsBH++DJIFPuK1bI2NNqSSLxlW5cA2EeXKjdYW IbRPfSZSSpNdw5xta7dxSkirLl584Z5cxQjyNtWpA/fDmwx5qSCVf0U2ACJ70eksOFjl5 uvP2wiDA/xeI+h/g2JZZzgwIzZ4JygkH2vZGhOwVA4DPuqDUdFh7dszjryhI6DZ6sW1ii DSM7nMYlgLZIpod12f+6HKElT/NexPuMSp/Ap71PmbXt/EAxVHd4MJae9n5WqFyxGgA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=fJuBEP0q; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.85.63 Received: from BYAPR05CU005.outbound.protection.outlook.com (mail-westusazon11010063.outbound.protection.outlook.com [52.101.85.63]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5C44606A31A; Wed, 2 Dec 2026 08:39:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D5C44606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=fJuBEP0q ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Y1HDF1WYpeJGHVVpTOpG/QROlH+S99bmKgq86P8XOsxXcYLdK3oxRGalVv7oLZGmFbweE/BYosQzRjckn6GxR1e165MLCD7+aQOpGT9YLUSD+7ju4qH/OL2JlWq0D5xD6x8fdfFgQwKjgHzLxC7pBnIi8Hn9Bql6/A8j6kwRBvrxecv7u48SfzdCppU7gdkrcl/+Xcspz4/RhRnsiEpwqOUrad0RtGQauq4HHDU9kPuwyZogk7USF5fTEUV4t1j31eZ+f5capz18FhktoHeklSzPw53TxJA9YDU9NC5rmw5+wdfW28wg/8k9gfj95J1FfB35nW4043MvJIm87Q+aSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WNFSarbeZ6RkMJmMTOIS3ifBMNtrQn7LLVYlJJKl26k=; b=r24bgz55s+4BFm5OZ2aZk+0HMAxtZF10OYBv4u/2J49vNTLLOe4MeXp9hIH1pYvyeA5CQLgyuvfY4x8MDZdMHHfWyC1xLayHci8mFbuFnEHeVr80MJMdC1FXoh7T4OXIsBW2Oor6OVgclvyrv0qYvN+qY4z6AtTLpOflyHPPykAI5yKGlz80HqDjELhNth9zbrej8JmBQNuRQacbzV9RuMeDAqfA/jJP07uppZtT7fjSE/PMRPDSG3GvGbgxakaslHV0JNYCcgEzgbwjUmixBb4358Bd6IqcXlMv33n7lHYiaMHQ61Laqqy+vf54G6OuFo+zDMWzxQOAcVgL8npAHw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WNFSarbeZ6RkMJmMTOIS3ifBMNtrQn7LLVYlJJKl26k=; b=fJuBEP0qVWdroXCQMbYBrTWR+CmXtHABflDdLQ8F5oZONBhEm5Hz7bS17iGL5a84EiF5hxPf4AHnyk6CReS08V9EsryU4yXEs416hf7KSutj26Hdq0l6Ut0ADhG3vSLGuelDd+Z0pWPQ9Kzk1xzUk1sVriDwLYXqDybxioqkp80mLYkopzgwxi+WiD/AkFdbKwo/DbJNlS9uj1YJi77gPIrAZ6+y7Ht4KaCTgUiYS7i9MpSSLoyGWawPE17L3e4NA87cUFoKwvXL+BTsr8YlYo5O0+qLrEi2Mhdf8dcwIc/jNl+Jiv//H7zYngMSs1DEQ5b83FKfu8w3zTiefYazsg== Received: from PH7PR10CA0008.namprd10.prod.outlook.com (2603:10b6:510:23d::14) by IA1PR12MB8556.namprd12.prod.outlook.com (2603:10b6:208:452::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Wed, 2 Dec 2026 08:38:55 +0000 Received: from BY1PEPF0001AE18.namprd04.prod.outlook.com (2603:10b6:510:23d:cafe::36) by PH7PR10CA0008.outlook.office365.com (2603:10b6:510:23d::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.10 via Frontend Transport; Wed, 2 Dec 2026 08:38:54 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BY1PEPF0001AE18.mail.protection.outlook.com (10.167.242.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Wed, 2 Dec 2026 08:38:54 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 00:38:34 -0800 Received: from kalok-SPC741D16QM3.nvidia.com (10.126.231.37) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 00:38:20 -0800 From: Alok Kumar To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v6 27/34] gpu: nova-core: vgpu: add GSP plugin RPC transactions Date: Wed, 2 Dec 2026 13:58:51 +0530 Message-ID: <12e49ee9498aa73c98a30c7807be1fd22d64fd35.1796191008.git.alkumar@nvidia.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY1PEPF0001AE18:EE_|IA1PR12MB8556:EE_ X-MS-Office365-Filtering-Correlation-Id: 1869eeca-e5f1-40ca-258e-08df504fb328 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|1800799024|7416014|376014|23010399003|82310400026|10067099003|56012099006|261026121527099003|261026140227099003|261028144727099003|261022105027099003|261021135927099003|261021121427099003|261022075727099003|261022113327099003|261102123227099003|261021123027099003|261009223027099003|22082099003|18002099003|11063799006|6133799003|3023799007; X-Microsoft-Antispam-Message-Info: CO+6eE1wi91SrE3zTdQLns8tQuki4clOa9Kdq/iqesW8SM10/J7Z4FlSreSjFwS6L85IrYIdxWKbYnB61N/nIPiISbQ0K61C8vPFfH7Xw0ZEMaO5uyrhFmiHsgz/IpmKGeKAKwr+5k5GgJ9UOQCdJ6uP//ZfhTZH0mqCa/VoMSza6EKXsPJrX9HlxZ43I84mafVc7PzduMMCtFbDEDC9YXUXvWELbUosjYm9oLo+Ook+fCQkQZxIB6e2vR0UGMVnDKueg47VOiQ0stbIDjlNytVeRw+7ku+7L1EGPPImIqQmMbd+V/coWTw3dw4D3HO7MCW/mBjIrBMuzClSAc3YomjNcH0kmYmm/f9GmKmYwcoL/ckrSEWI28s0mTz14tUhRadO/CkjiRcUlyEuCGADFkgcbuZq3bhx4MCSdhM+n5HyspyA+86LVUNPvRJtOfl7Q05Ak7AtTKohGXuiRvOwnMq1aeVVymgst4rtil7rYTpesecG0TL4WacKdVsETI40BCTXc7YlKlThzUnw0msEqJhSYR67Xe9CZgMOzBBPfo4WoArx108P1NxK/l/ZWiXk9KvIc0RGHatJRz2QeQamFgygJFCSEmHeAYRohrwhHtF2tpirMq0CcdQXdAnihicgJPtib8gAjPq2VYVw/vcoIcaNPtyr+G0BR4dgYgBBExiEo34Yu3+8UYT0TWykzMnVmO5LN+pBYKyefqvK4MdqBg== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(36860700016)(1800799024)(7416014)(376014)(23010399003)(82310400026)(10067099003)(56012099006)(261026121527099003)(261026140227099003)(261028144727099003)(261022105027099003)(261021135927099003)(261021121427099003)(261022075727099003)(261022113327099003)(261102123227099003)(261021123027099003)(261009223027099003)(22082099003)(18002099003)(11063799006)(6133799003)(3023799007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZJzljkaRKK4TuKsHpQ49WB/2jGNEeQYjY7v8iJ2RsEBSQwDdavxmkPDvzkTyyWt8xzXucZ+bzHdJxCG7yk+uOdA0mKgXtwwTE8hffqLJYSn8EXaGYsgH/roWyNTXX7uyR16ON1RHbmNUTDCwfaG0k9NWh35z+4Az6BrewVTqx4ZSeWEPne8SK0oeWthAGeibwZMU+3pnqq7swGkjlde6Xt1C3teuSiSn8szf0GvkV1K4gN1SUDdG4Ve74/EM/vaqe3Jcc6vA+i0aaXb/KZFTe+zmzWiRTTR3mbC6VjL/R+yqUrCMYJ0gEM+d6RhZB2Je1g8FIeLPwkOGSX99pr8wFKnLSXEp59ApP5zjz34XMPAgBJRJBHmK2AEgX8SVmuh6HVGWC88lWbp6+Ku5SjJEBT6ifpaolBiTgXHGCLxAy0h74DzSoXFrcwIdPHLgbdV+ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 08:38:54.8033 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1869eeca-e5f1-40ca-258e-08df504fb328 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BY1PEPF0001AE18.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8556 From: Zhi Wang A GSP plugin consumes a shared-buffer request after its VF doorbell is rung and publishes completion in the response region. Add PluginRpc to own the communication mapping together with the instance's stable BAR0 and validated GFID. Accept typed RPC message IDs, copy the payload before publishing its sequence, advance the local sequence, ring and read back the doorbell, then wait for a matching completion and check its firmware status. Keep one sequence identity for each published request, including a request whose doorbell or wait later fails, and bound completion polling with the RPC timeout. Delegate explicit unmap to the owned communication region so teardown errors retain its owner; ordinary drop releases the mapping through BarMapping. Signed-off-by: Zhi Wang Signed-off-by: Alok Kumar --- drivers/gpu/nova-core/gpu.rs | 1 + drivers/gpu/nova-core/regs.rs | 31 +++- drivers/gpu/nova-core/vgpu.rs | 6 + drivers/gpu/nova-core/vgpu/fw.rs | 13 ++ drivers/gpu/nova-core/vgpu/fw/commands.rs | 10 ++ drivers/gpu/nova-core/vgpu/gsp_plugin_comm.rs | 37 +++- drivers/gpu/nova-core/vgpu/gsp_plugin_rpc.rs | 159 ++++++++++++++++++ drivers/gpu/nova-core/vgpu/instance.rs | 13 +- 8 files changed, 261 insertions(+), 9 deletions(-) create mode 100644 drivers/gpu/nova-core/vgpu/gsp_plugin_rpc.rs diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs index 935b31e9f047..efed67fc0d9e 100644 --- a/drivers/gpu/nova-core/gpu.rs +++ b/drivers/gpu/nova-core/gpu.rs @@ -609,6 +609,7 @@ pub(crate) fn new<'a>( VgpuState::Enabled { .. } => Some(KBox::pin_init( VgpuManager::new( dev, + bar, &gsp_resources.get_ref().gsp.cmdq, bar_user.get_ref(), mm.get_ref(), diff --git a/drivers/gpu/nova-core/regs.rs b/drivers/gpu/nova-core/regs.rs index 050054a2b23d..867fc591b43d 100644 --- a/drivers/gpu/nova-core/regs.rs +++ b/drivers/gpu/nova-core/regs.rs @@ -7,13 +7,17 @@ Io, Mmio, // }, + prelude::*, sizes::SizeConstants, time, // }; use pin_init::Zeroable; use crate::{ - driver::NovaRegisters, + driver::{ + Bar0, + NovaRegisters, // + }, falcon::{ DmaTrfCmdSize, FalconCoreRev, @@ -39,6 +43,31 @@ pub(crate) NV_PBUS_SW_SCRATCH(u32)[64] @ 0x00001400 {} } +// VIRTUAL_FUNCTION + +register! { + base: NovaRegisters; + + // PF BAR0 exposes the virtual-function register window at 0x00b8_0000. + pub(crate) NV_VIRTUAL_FUNCTION_PRIV_DOORBELL(u32) @ 0x00b8_2200 { + 31:0 handle; + } +} + +impl NV_VIRTUAL_FUNCTION_PRIV_DOORBELL { + const DOORBELL_STRIDE: u32 = 32; + const DOORBELL_VECTOR: u32 = 17; + + /// Notify the GSP plugin for the given guest function and read back the doorbell. + pub(crate) fn ring_gsp_plugin(bar0: Bar0<'_>, gfid: u16) -> Result { + // A `u16` GFID produces a handle of at most 0x1f_fff1, which fits in `u32`. + let value = u32::from(gfid) * Self::DOORBELL_STRIDE + Self::DOORBELL_VECTOR; + bar0.try_write_reg(Self::zeroed().with_handle(value))?; + bar0.try_read(NV_VIRTUAL_FUNCTION_PRIV_DOORBELL)?; + Ok(()) + } +} + // PGC6 register space. // // `GC6` is a GPU low-power state where VRAM is in self-refresh and the GPU is powered down (except diff --git a/drivers/gpu/nova-core/vgpu.rs b/drivers/gpu/nova-core/vgpu.rs index 1e4c510ea4dd..2d60bb5951e5 100644 --- a/drivers/gpu/nova-core/vgpu.rs +++ b/drivers/gpu/nova-core/vgpu.rs @@ -13,6 +13,7 @@ }; use crate::{ + driver::Bar0, fsp::{ Fsp, VgpuMode, // @@ -37,6 +38,7 @@ mod commands; mod fw; mod gsp_plugin_comm; +mod gsp_plugin_rpc; mod hal; mod instance; mod vram; @@ -137,6 +139,7 @@ struct VgpuManagerInner<'gpu> { #[pin] instances: Mutex>, dev: &'gpu device::Device, + bar: Bar0<'gpu>, cmdq: &'gpu Cmdq<'gpu>, bar_user: &'gpu BarUser<'gpu>, mm: &'gpu SharedGpuMm<'gpu>, @@ -149,8 +152,10 @@ struct VgpuManagerInner<'gpu> { impl<'gpu> VgpuManager<'gpu> { /// Retains runtime parameters from a completed vGPU-enabled GSP boot. + #[expect(clippy::too_many_arguments)] pub(crate) fn new( dev: &'gpu device::Device, + bar: Bar0<'gpu>, cmdq: &'gpu Cmdq<'gpu>, bar_user: &'gpu BarUser<'gpu>, mm: &'gpu SharedGpuMm<'gpu>, @@ -164,6 +169,7 @@ pub(crate) fn new( inner <- pin_init!(VgpuManagerInner { instances <- new_mutex!(VgpuInstances::new(), "nova-core::vgpu-instances"), dev, + bar, cmdq, bar_user, mm, diff --git a/drivers/gpu/nova-core/vgpu/fw.rs b/drivers/gpu/nova-core/vgpu/fw.rs index 84a89c32a77b..76bd2b7e4e52 100644 --- a/drivers/gpu/nova-core/vgpu/fw.rs +++ b/drivers/gpu/nova-core/vgpu/fw.rs @@ -12,6 +12,8 @@ // Alias to avoid repeating the version number with every use. use r000_00 as bindings; +pub(super) use commands::RpcMessage; + pub(super) use bindings::{ GSP_PLUGIN_BOOTLOADED, VGPU_CPU_GSP_COMMUNICATION_BUFF_TOTAL_SIZE, @@ -28,3 +30,14 @@ VGPU_CPU_GSP_RESPONSE_BUFF_REGION_SIZE, VGPU_CPU_GSP_VGPU_TASK_LOG_BUFF_REGION_SIZE, // }; + +/// State observed in the response buffer for an expected RPC sequence. +pub(super) enum RpcResponse { + Pending { + /// Last sequence completed by firmware. + sequence: u32, + }, + Complete { + status: u32, + }, +} diff --git a/drivers/gpu/nova-core/vgpu/fw/commands.rs b/drivers/gpu/nova-core/vgpu/fw/commands.rs index 5af0790ce3cf..d900075a96b0 100644 --- a/drivers/gpu/nova-core/vgpu/fw/commands.rs +++ b/drivers/gpu/nova-core/vgpu/fw/commands.rs @@ -28,6 +28,16 @@ vgpu::Dbdf, // }; +use super::bindings; + +/// Message types supported by the nova-core plugin RPC channel. +#[expect(dead_code)] +#[derive(Clone, Copy)] +#[repr(u32)] +pub(crate) enum RpcMessage { + VersionNegotiation = bindings::MESSAGE_NV_VGPU_CPU_RPC_MSG_VERSION_NEGOTIATION, +} + #[derive(Clone, Copy)] struct SwizzId(u32); diff --git a/drivers/gpu/nova-core/vgpu/gsp_plugin_comm.rs b/drivers/gpu/nova-core/vgpu/gsp_plugin_comm.rs index 126ba9ad99cf..2e3415b9f8d9 100644 --- a/drivers/gpu/nova-core/vgpu/gsp_plugin_comm.rs +++ b/drivers/gpu/nova-core/vgpu/gsp_plugin_comm.rs @@ -29,7 +29,9 @@ use super::fw::{ self, RawControlRegion, - RawResponseRegion, // + RawResponseRegion, + RpcMessage, + RpcResponse, // }; /// Layout of the plugin communication region, located at the start of the management heap. @@ -157,7 +159,6 @@ pub(super) fn is_plugin_ready(&self) -> Result { } /// Initialize the shared control and response buffers for plugin RPC. - #[expect(dead_code)] pub(super) fn initialize(&self) -> Result { let comm = self.view()?; let control = io_project!(comm, .control.__bindgen_anon_1); @@ -205,6 +206,38 @@ pub(super) fn initialize(&self) -> Result { Ok(()) } + /// Copy and publish one RPC request to firmware. + pub(super) fn submit(&self, message: RpcMessage, sequence: u32, data: &[u8]) -> Result { + let comm = self.view()?; + let control = io_project!(comm, .control.__bindgen_anon_1); + let buffer = io_project!(comm, .message); + + if data.len() > buffer.size() { + return Err(E2BIG); + } + io_project!(buffer, [try: ..data.len()]).copy_from_slice(data); + + // CAST: `RpcMessage` has a `u32` representation. + io_write!(control, .message_type, message as u32); + io_write!(control, .message_seq_num, sequence); + + Ok(()) + } + + /// Read firmware's response for an expected RPC sequence. + pub(super) fn response(&self, expected_sequence: u32) -> Result { + let response = io_project!(self.view()?, .response.__bindgen_anon_1); + + let sequence = io_read!(response, .message_seq_num_processed); + if sequence != expected_sequence { + return Ok(RpcResponse::Pending { sequence }); + } + + Ok(RpcResponse::Complete { + status: io_read!(response, .result_code), + }) + } + /// Invalidate the PTEs and release the communication mapping. pub(super) fn unmap(&mut self) -> Result { self.map.unmap() diff --git a/drivers/gpu/nova-core/vgpu/gsp_plugin_rpc.rs b/drivers/gpu/nova-core/vgpu/gsp_plugin_rpc.rs new file mode 100644 index 000000000000..e63f4c660c0a --- /dev/null +++ b/drivers/gpu/nova-core/vgpu/gsp_plugin_rpc.rs @@ -0,0 +1,159 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + +//! GSP plugin RPC. +//! +//! ```text +//! Host (PluginRpc) Shared RPC buffer (VRAM) GSP plugin +//! | | | +//! |-- BAR1: payload --------->| Message | +//! |-- BAR1: type, sequence -->| Control | +//! | | | +//! |-- BAR0: VF doorbell ----------------------------->| +//! | |<-- read request ------| +//! | | | process RPC +//! | |<-- completion --------| +//! |-- poll processed seq ---->| Response | +//! |<-- matching seq, status --| | +//! ``` + +use kernel::{ + device, + prelude::*, + time::{ + delay::fsleep, + Delta, + Instant, + Monotonic, // + }, +}; + +use crate::{ + driver::Bar0, + regs::NV_VIRTUAL_FUNCTION_PRIV_DOORBELL, // +}; + +use super::{ + fw::{ + RpcMessage, + RpcResponse, // + }, + gsp_plugin_comm::CommBufferRegion, + instance::Gfid, // +}; + +/// BAR1-backed channel used to communicate with one GSP plugin. +pub(super) struct PluginRpc<'pool, 'map, 'gpu> { + comm: CommBufferRegion<'pool, 'map, 'gpu>, + bar0: Bar0<'gpu>, + gfid: Gfid, + message_sequence: u32, +} + +impl<'pool, 'map, 'gpu> PluginRpc<'pool, 'map, 'gpu> { + pub(super) fn new( + comm: CommBufferRegion<'pool, 'map, 'gpu>, + bar0: Bar0<'gpu>, + gfid: Gfid, + ) -> Self { + Self { + comm, + bar0, + gfid, + message_sequence: 0, + } + } + + pub(super) fn comm(&self) -> &CommBufferRegion<'pool, 'map, 'gpu> { + &self.comm + } + + /// Initialize the control and response buffers for the first RPC. + #[expect(dead_code)] + pub(super) fn init_rpc(&mut self) -> Result { + self.comm.initialize()?; + self.message_sequence = 0; + Ok(()) + } + + fn next_sequence(&self) -> u32 { + let sequence = self.message_sequence.wrapping_add(1); + if sequence == 0 { + 1 + } else { + sequence + } + } + + /// Write one RPC message, ring the VF doorbell, and wait for its response. + #[expect(dead_code)] + pub(super) fn rpc_call( + &mut self, + dev: &device::Device, + message_type: RpcMessage, + data: &[u8], + ) -> Result { + let sequence = self.next_sequence(); + self.comm.submit(message_type, sequence, data)?; + self.message_sequence = sequence; + + dev_dbg!( + dev, + "vGPU RPC: gfid={} type={} bytes={} sequence={}\n", + self.gfid.get(), + // CAST: `RpcMessage` has a `u32` representation. + message_type as u32, + data.len(), + sequence, + ); + + NV_VIRTUAL_FUNCTION_PRIV_DOORBELL::ring_gsp_plugin(self.bar0, self.gfid.get())?; + self.wait_response(dev, sequence) + } + + fn wait_response(&self, dev: &device::Device, expected_sequence: u32) -> Result { + let start = Instant::::now(); + let timeout = Delta::from_secs(120); + + loop { + match self.comm.response(expected_sequence)? { + RpcResponse::Complete { status } => { + if status != 0 { + dev_dbg!( + dev, + "vGPU RPC: sequence {} failed with status {}\n", + expected_sequence, + status, + ); + return Err(EIO); + } + + dev_dbg!( + dev, + "vGPU RPC: sequence {} completed after {:?}\n", + expected_sequence, + start.elapsed(), + ); + return Ok(()); + } + RpcResponse::Pending { sequence } => { + if start.elapsed() >= timeout { + dev_dbg!( + dev, + "vGPU RPC: sequence {} timed out; last response was {}\n", + expected_sequence, + sequence, + ); + return Err(ETIMEDOUT); + } + } + } + fsleep(Delta::from_millis(1)); + } + } + + /// Release the BAR1 mapping. + pub(super) fn unmap(&mut self) -> Result { + self.comm.unmap() + } +} diff --git a/drivers/gpu/nova-core/vgpu/instance.rs b/drivers/gpu/nova-core/vgpu/instance.rs index 892347f073ff..062cf963e7f7 100644 --- a/drivers/gpu/nova-core/vgpu/instance.rs +++ b/drivers/gpu/nova-core/vgpu/instance.rs @@ -42,6 +42,7 @@ VgpuProperties, // }, gsp_plugin_comm::CommBufferRegion, + gsp_plugin_rpc::PluginRpc, vram::{ VgpuVramLayout, VgpuVramSlot, @@ -147,7 +148,7 @@ struct VgpuInstance<'pool, 'gpu> { vgpu_type: VgpuType, vm_pid: u32, num_plugin_channels: u32, - comm: CommBufferRegion<'pool, 'gpu, 'gpu>, + plugin_rpc: PluginRpc<'pool, 'gpu, 'gpu>, // Unmap the communication region before returning its slot and channel IDs. vram_slot: VgpuVramSlot<'pool>, chids: ChannelIdReservation<'gpu>, @@ -176,7 +177,7 @@ fn teardown(&mut self, vgpu: &VgpuManagerInner<'gpu>) -> Result { send_cleanup(vgpu.dev, vgpu.cmdq, self.gfid)?; self.needs_teardown = false; } - self.comm.unmap() + self.plugin_rpc.unmap() })(); if let Err(error) = result { self.failure = Some(error); @@ -193,7 +194,7 @@ fn bootload( ) -> Result { let fb = &self.vram_slot.fbmem; let mgmt = &self.vram_slot.mgmt_heap; - let logs = self.comm.plugin_logs()?; + let logs = self.plugin_rpc.comm().plugin_logs()?; let payload = encode_vgpu_bootload(BootloadInfo { dbdf: self.dbdf, @@ -221,11 +222,11 @@ fn bootload( payload.len() * size_of::(), ); - self.comm.clear_plugin_ready()?; + self.plugin_rpc.comm().clear_plugin_ready()?; self.needs_teardown = true; send_bootload(dev, cmdq, &payload)?; - wait_plugin_ready(dev, &self.comm)?; + wait_plugin_ready(dev, self.plugin_rpc.comm())?; dev_dbg!(dev, "bootload: gfid={} plugin ready\n", self.gfid.get()); Ok(()) @@ -409,7 +410,7 @@ fn allocate_instance( vgpu_type, vm_pid, num_plugin_channels: PLUGIN_CHANNELS_PER_ENGINE, - comm, + plugin_rpc: PluginRpc::new(comm, vgpu.bar, gfid), vram_slot, chids, needs_teardown: false,