From nobody Sun Dec 14 12:11:04 2025 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11023138.outbound.protection.outlook.com [40.93.201.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DED7521CA00; Thu, 16 Oct 2025 21:02:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.201.138 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760648560; cv=fail; b=pJSkGFxXdLdMebfuuQLBcfGC1MnRgTDSvV+XgqguE0lDwT1xYe7ccuEjQxCbhpmgOcIb2WG3JiJQUM0TsJPNwEp2fwWQ4NshcDI8OKVixl7d9CV+CY1yzFLwBz5XMqFHD45JlAQAq5oNvn+jaMNrNqKmmA2j/W+HYagWYk6zBnU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760648560; c=relaxed/simple; bh=T4iQJgbqn9MuxGoQBAmWTU7YsU3Zp6RhG4Dl0DozHao=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=b3V3voUv2RZhOKP9O/NgA2Fbv4kpuXlDBjAKv+sLfdS/XYx5P5ikjv0q/lrZykNxLS3swgZgElZiEceHTGsyg7kBfawHa1bAV5nDFmEhjcDV+azN68OoVIreGs2vWYhtfx4RuKK/uoeveqSvpWY8KU3K9mQhb/gYRLruJQH1O+M= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=os.amperecomputing.com; spf=pass smtp.mailfrom=os.amperecomputing.com; dkim=pass (1024-bit key) header.d=os.amperecomputing.com header.i=@os.amperecomputing.com header.b=giN2j/ma; arc=fail smtp.client-ip=40.93.201.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=os.amperecomputing.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=os.amperecomputing.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=os.amperecomputing.com header.i=@os.amperecomputing.com header.b="giN2j/ma" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=O2Rj0/IgatHMkzJbFVngXq5ZiD01MEYZZo+IUvV2u60Z1oikPXaNp/29bWw3JXU+qrjQ/f6XUvSAwkEdJ9NZ6o/NJ+mqHF6vTNl4Qd9pzpt+YD4L7frwpwK64xykFgCr3M4pwfPAFW4w6zNdMy+SHwKRagC7Br8XCNWji0qkp0kQxFzG3+Gwy9MUxc0Umny79mKzzXLYYWiMpqIHNf0KtTNNIInx5eGf40TF78iq3SJ2DZZYMn+Ts+Xh6cOhZGRKgIbcyvfMB1MH8nOR0auS17jkc53e44f5lJs9CkXEh5ntFDKn7xZxPuJ2/c+7QxlYcAcWpzNOEJqFQdT5IKcy5w== 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=xcZ34gbBO1m78hk3RjctoaITbEU0NquTYFn5sujIjic=; b=OY9WX/BooSWyNyinOYAC+u3lN8HWDq3udD7CJxAKhnoZz/Iz7NWl4uxtKNhuHB2wHGejlvrkFBNeARz2zCueFOXeh2XCmleMEJFlSp6ydQdvhjBfqGIaXNEUCoB23G9crN9shzMl4AkwWUtlLLvSBI1zIQQk0YAJRE3pgQaDT/U82dRAs5ASM2DpgxMHm6NAaduieuSSEbWs7xwfsG0eXQrd967c1yvIcVFhF34yMLRPAOs9sXqgZ9IoiNd6xnRFqswnJOvyrbyWIhvD5ah5nCJF5cHovaNXVEVkv6S5OLfpogaYXDL5eioilTa6qeXhK7k0cFwvZJL3QRfXD2XsmQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xcZ34gbBO1m78hk3RjctoaITbEU0NquTYFn5sujIjic=; b=giN2j/maiqteJp+5S9Mc94PbRZYhqPlN0qzqB/wrUuYhEXLhThkIxVF2ZNaNuipPVR2u72q6j3ddj98KvJOSwo21idVGwRv0lNZK9JzqmJRdgPR39hMOallIc08+OL5xbsrFAtdruu4777va2OcGo91QZYQQ/TJutOdmdOMW4aI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from BN3PR01MB9212.prod.exchangelabs.com (2603:10b6:408:2cb::8) by LV2PR01MB7813.prod.exchangelabs.com (2603:10b6:408:171::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9228.13; Thu, 16 Oct 2025 21:02:37 +0000 Received: from BN3PR01MB9212.prod.exchangelabs.com ([fe80::3513:ad6e:208c:5dbd]) by BN3PR01MB9212.prod.exchangelabs.com ([fe80::3513:ad6e:208c:5dbd%3]) with mapi id 15.20.9228.009; Thu, 16 Oct 2025 21:02:37 +0000 From: Adam Young To: Sudeep Holla , Jassi Brar Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jeremy Kerr , Matt Johnston , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Cameron , Huisong Li Subject: [PATCH v30 1/3] mailbox: pcc: Type3 Buffer handles ACK IRQ Date: Thu, 16 Oct 2025 17:02:19 -0400 Message-ID: <20251016210225.612639-2-admiyo@os.amperecomputing.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251016210225.612639-1-admiyo@os.amperecomputing.com> References: <20251016210225.612639-1-admiyo@os.amperecomputing.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CYZPR14CA0014.namprd14.prod.outlook.com (2603:10b6:930:8f::12) To BN3PR01MB9212.prod.exchangelabs.com (2603:10b6:408:2cb::8) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PR01MB9212:EE_|LV2PR01MB7813:EE_ X-MS-Office365-Filtering-Correlation-Id: d774d308-fe53-4d98-b434-08de0cf755d5 X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|7416014|366016|10070799003|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?ADBOfBzvrHjxo3+sWtpO7TkKlUQ84cqoSv39jf/jw3engVLDyq9YdtUmf13y?= =?us-ascii?Q?MOYd0ajaRWCZVvt3mAH0tclCjaVoaO4Y6UNak83PtmNu0SXYjrYLuY5wjSBe?= =?us-ascii?Q?IfG4edv25+M35r8tS5FVoTF/9MB80FtDyD9FiKgVajIPpiJ5PMmHPDPezSR2?= =?us-ascii?Q?enuEHpKUnLEVHBv5VC8BNE+DeiroVndP9pYIGZNvHbGJazdnSegbD7qCKyLH?= =?us-ascii?Q?49+bDeNP6EhTdwS71p30qZZAHMu4WG7/MyBuptkYGESb7MpKAVTqtu1qTqt3?= =?us-ascii?Q?6Wz+CLWtSuvR6UJXzaWilCtnxw2W0vv/HC5DpwXwsBWcEZNIC6C8VMJqC5sE?= =?us-ascii?Q?ke0r3dNHZAU5pZZu2ByBAK+4OWCbsZ15y1tbABcza6dRZeSLq/1jw/CXJ3ev?= =?us-ascii?Q?nnU3EWAKP93n/Sa2cevd98blHJqu9wvbmgP1B3OZ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Sw5+mm4TICjPiTzPRRuFMm8iaUDRQJvzyWg3xCsj31KQbNbXPp/GUL?= =?us-ascii?Q?h51Etheik3saRPWbHCr1xxAXzJZeLyaymMeZvuDxR/tj4HAeS4abzz7g2XX3?= =?us-ascii?Q?ch0WV1GrWVTnZQ68acWG65fAygRnPAvh?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN3PR01MB9212.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(52116014)(7416014)(366016)(10070799003)(1800799024);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?BlMOhFqHHihKvcoi+/+D3s+OmTFsDMvV97A6MWW7D1XPTQUtK2Ot1nd3QGOs?= =?us-ascii?Q?qhrCmfEyzXdE5doxGNE4OFZfntAnT94QqqD6sdlXj+YWPNo65UEitlSr97GK?= =?us-ascii?Q?Ehdj2d9+5g9W4c0+fBZ8wPGUSpwUXTq0t/wY9UAOLI2Ik50yN4iR6TG9AYkp?= =?us-ascii?Q?ezl0pTfjoH0RrPG0rkNmpnoIcpViS7geFk1ST0PNJfFQs0HAFOwQUMu7oB+1?= =?us-ascii?Q?jhv4JRelTc+QS4dAM8s1C+Ah8+H7cGFYV1m2y9WX++QK3mHonabGNz6JPVYy?= =?us-ascii?Q?Vf++es/MeZzZ54PYMJKhKO3eiG8M+/YI/E5oPKzULi2Kpmx/CI2yULbgmlaW?= =?us-ascii?Q?DA0Gl0h3Uj48oLTagVw25FIf7xJlYopoVbKnORnU33CUIFFHUB5ll4I7D8EN?= =?us-ascii?Q?A7mAF1oO4L7BZXcxWHnLXcydTwOoprAZsRX65r3h5OG5GMX4rtpezgL0r4dN?= =?us-ascii?Q?FTf29EUehbl9vs9gHyyxbP4r9X/G8mp3jDli1Fxdd8hpO4vksTnkn27y4EWt?= =?us-ascii?Q?F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clohfl08j6i?= =?us-ascii?Q?LeiVGmXG1Z6rRT0nckItdjGVAD7FnG85n/vj3c4NKBmb8Vb5ili1qK7z8dsV?= =?us-ascii?Q?ehkJ3y/xlrj/2LXem6fOZhlsLY+c6EjN/kEbXsZiqkk4dwi0J6FJ0BfmLO0b?= =?us-ascii?Q?kCGFpYIPuNMOneUvNqxgS+N1t6jG95NoijUd6CFyAqVwiPMjvIgKWszfU4bl?= =?us-ascii?Q?x3jJ4sibBDLa/+PIixz2/bHjkvEfsCQrw3xr0h5QKcIgcBVD8sx4krAJGEBh?= =?us-ascii?Q?VTQY87dbHndaSqD3KCj6PTSkEVc=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: d774d308-fe53-4d98-b434-08de0cf755d5 X-MS-Exchange-CrossTenant-AuthSource: BN3PR01MB9212.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2025 21:02:37.1186 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: H2uXwdyffTWhdSMmqEP1dMcA9GZ9j5EG9Uspd7ZYYt0FbeWOTJEdWeIE99oh7jvUfgNRsNsQcvGUi0dCXYSQ0/GB/ctTgsVr4/lRFHgH3zYVh3T2BYvAevUiSRRfc29b X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR01MB7813 Content-Type: text/plain; charset="utf-8" The PCC protocol type 3 requests include a field that indicates that the recipient should trigger an interrupt once the message has been read from the buffer. The sender uses this interrupt to know that a transmission is complete, and it is safe to send additional messages. Signed-off-by: Adam Young mailbox/pcc extended memory helper functions --- drivers/mailbox/pcc.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c index f6714c233f5a..978a7b674946 100644 --- a/drivers/mailbox/pcc.c +++ b/drivers/mailbox/pcc.c @@ -306,6 +306,18 @@ static void pcc_chan_acknowledge(struct pcc_chan_info = *pchan) pcc_chan_reg_read_modify_write(&pchan->db); } =20 +static bool pcc_last_tx_done(struct mbox_chan *chan) +{ + struct pcc_chan_info *pchan =3D chan->con_priv; + u64 val; + + pcc_chan_reg_read(&pchan->cmd_complete, &val); + if (!val) + return false; + else + return true; +} + /** * pcc_mbox_irq - PCC mailbox interrupt handler * @irq: interrupt number @@ -340,6 +352,14 @@ static irqreturn_t pcc_mbox_irq(int irq, void *p) * required to avoid any possible race in updatation of this flag. */ pchan->chan_in_use =3D false; + + /** + * The remote side sent an ack. + */ + if (pchan->type =3D=3D ACPI_PCCT_TYPE_EXT_PCC_MASTER_SUBSPACE && + chan->active_req) + mbox_chan_txdone(chan, 0); + mbox_chan_received_data(chan, NULL); =20 pcc_chan_acknowledge(pchan); @@ -490,6 +510,7 @@ static const struct mbox_chan_ops pcc_chan_ops =3D { .send_data =3D pcc_send_data, .startup =3D pcc_startup, .shutdown =3D pcc_shutdown, + .last_tx_done =3D pcc_last_tx_done, }; =20 /** --=20 2.43.0 From nobody Sun Dec 14 12:11:04 2025 Received: from CY7PR03CU001.outbound.protection.outlook.com (mail-westcentralusazon11020088.outbound.protection.outlook.com [40.93.198.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F083A2E4241; Thu, 16 Oct 2025 21:02:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.198.88 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760648564; cv=fail; b=h/HbYE84uPbAHujnF1FXqRBEsbkmfgNADgiCa0smDSICi0DrTCM7nDd2EgUbb40OVvmQzDsvol7LrWGqpKoG3wvGCfMQDZZ6Q8e5rdoOGVhpiw7OKUFJzqe8+SN/kyA1jXJTnZBI1zdqnYZYGr2ecLQg2CFHONhGD+tEyKTuPM8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760648564; c=relaxed/simple; bh=n9TdpqXyL/m0/aa0fEfrmyZ9imoQ5KKsmi4uwAKdQI8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=a7pychX9euVTc1axogRsqpwYwqSpjHr/x9WXtLMJvMuj8fmapRZvHovRq1Z87hC5iSZGTZDhluXE2bE0qVGy9XtGDMBPhpc6kWPMUd3UxV0yp0lZ5bHn+suTYC3mQrCf0NnhOQC1KW0E53nBEuxdVMhxENY3fSVH00mz5i1vKu0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=os.amperecomputing.com; spf=pass smtp.mailfrom=os.amperecomputing.com; dkim=pass (1024-bit key) header.d=os.amperecomputing.com header.i=@os.amperecomputing.com header.b=F0WWDzSV; arc=fail smtp.client-ip=40.93.198.88 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=os.amperecomputing.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=os.amperecomputing.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=os.amperecomputing.com header.i=@os.amperecomputing.com header.b="F0WWDzSV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=eCT56ZL7svMtq0IYmfDkIIrV2m+Oa6iuWNOWlZFbONcortYMJdmrE6Je4Re0ymvEQ6d8/Jn81wa+TTQJKc/09i9WNzQWFqASo+BzSdiVIBHdvhKawfpffnThNx1mB2vMRFW+reJly6uEjpbvpmKLvJCFt4wo3sT9/j2nTu3chmo84mKPLwvsVZ3OZ/cEnHm6etnnodWtMsw8L7N9e9GG83hilB6/rJYsMcxeCz9+NsC9/+yYoAqMP09NhQ6Mj073v4jfDaO3YwMHTySGOIX5TJLlaMVwUidYjgbCieVYmycI0GaU+3zIj9lVlTqgAhmmCxEEwFsGAkJsJiDzRztnWQ== 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=1X6Qv+hsrnR3JTGUbCGWIyPZUYsnRb4apcYKid5+7XA=; b=iIxvfkiQfFvk0v+W7tyYyq8R2TfKu9xVwXqfkv3HA2vcqGlrOH11HWSqxYm0WUzjtpgNMKMSTFA79YwFyE4JFWTjlnEKgyCQy7MOvKTylCdkNsip946HUhx2o8lkzLZaczNk/Ddi+h1e0OUzZGrW7eqsBfbm9miqSg0nFYddVw+blbgu+PIsgkAzjSZUvHYgMRyUegr/Z8SFBUZ+PCgU1WYjPxHq3xN/VZ+WHnj5eJDU16oLUAUyATDo6IzT3Qhe8/fnMmeB3oo64n2LIAtg6d7pKNsXkILkKVyWYDKG2KQg8oc8VImzXb9ejxWESBv9PL9FoGHoJFdgpfu6LFTh/Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1X6Qv+hsrnR3JTGUbCGWIyPZUYsnRb4apcYKid5+7XA=; b=F0WWDzSVnRq4zF2AClryWuyGGDTEP6BiJlGpQ3lZZ0RkiRBZMUnOA8gbX0QYl1wKOJlTr7zA/30C27fIlC81Cces8xkmkWHXa9obxis3kL1OizAUxmoFvyiH8LTpKM7PvQAAHgkiOmH8CJrDjC04T6P4AZRWXZEtegnK7nXS0IM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from BN3PR01MB9212.prod.exchangelabs.com (2603:10b6:408:2cb::8) by LV2PR01MB7813.prod.exchangelabs.com (2603:10b6:408:171::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9228.13; Thu, 16 Oct 2025 21:02:41 +0000 Received: from BN3PR01MB9212.prod.exchangelabs.com ([fe80::3513:ad6e:208c:5dbd]) by BN3PR01MB9212.prod.exchangelabs.com ([fe80::3513:ad6e:208c:5dbd%3]) with mapi id 15.20.9228.009; Thu, 16 Oct 2025 21:02:41 +0000 From: Adam Young To: Sudeep Holla , Jassi Brar , "Rafael J. Wysocki" , Len Brown , Robert Moore Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jeremy Kerr , Matt Johnston , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Cameron , Huisong Li Subject: [PATCH v30 2/3] mailbox: pcc: functions for reading and writing PCC extended data Date: Thu, 16 Oct 2025 17:02:20 -0400 Message-ID: <20251016210225.612639-3-admiyo@os.amperecomputing.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251016210225.612639-1-admiyo@os.amperecomputing.com> References: <20251016210225.612639-1-admiyo@os.amperecomputing.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CYZPR14CA0021.namprd14.prod.outlook.com (2603:10b6:930:8f::22) To BN3PR01MB9212.prod.exchangelabs.com (2603:10b6:408:2cb::8) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PR01MB9212:EE_|LV2PR01MB7813:EE_ X-MS-Office365-Filtering-Correlation-Id: 44523f82-b3b1-44ee-e518-08de0cf7581d X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|7416014|366016|10070799003|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?zaM97YuWWS5cy1RJbBrbjLb0Gog7RNpO+iO4w4jIJ1aiqKx3SPGQbWbFE9em?= =?us-ascii?Q?8Now4J3ETjNQi1zQOlZtT6GZwGfn4x5PBRco/hz81HVumcUKtJYM4v9I59cL?= =?us-ascii?Q?h8qst7Q4oHD2Vpvu2zqEgE+5jM+oVmiwrWGE6KkYDMVo2n3WiH8kLcHPJt9u?= =?us-ascii?Q?bW2h4gjXP6+MCVoFwKj+vNxePjVfAkJYotYXEFQPJCzKMAumOseXiZ7T701C?= =?us-ascii?Q?taVGvpFFytNalcFP4+9KsS8dU6tKMS9JmtFLBIb7IOL6EM081/DAgHKK9zvL?= =?us-ascii?Q?7LebPeq/DZKh5RIbx9WNIsx7pqNGBFwMSABjuKm1YiFU1sKJdwX2h4qB3Vev?= =?us-ascii?Q?obfz01f6ukn6QPCWY6xMt6bKnJp+YkRZau+mJyttnps6EXU48MEpKYRmQupb?= =?us-ascii?Q?BOAqWD1RSLIh3qgzLli04zgmjhVNVx1Q8sk1bjJRCLpuiK8Lc0pyxCD62Vrw?= =?us-ascii?Q?6FkLP+9rtIq+rcHXT/RDB72+vwlZ+FdwXLy6nlIIWhmDh8jyo/l6seCRAlGY?= =?us-ascii?Q?Whil0BBQeJVOzoTYu17bIreXzBO/x6Nos5MQRdtm5/TEttRq66da9Kje8Jow?= =?us-ascii?Q?7TtdKZToDPXSxgdVTg0Y8Lf2cI9x5TAW+qxMAQn3KfVEMkGijaAGu+o2Ar1w?= =?us-ascii?Q?sLv+fmLSZmQL1F/1etAqtHFcZvXVY5wz4M7U8HWN2++aUlG/vFIPQrly7KOu?= =?us-ascii?Q?5PjK5lY8FnSvKNNShX79e069OxVw5rvyGN3rbfmm0d1lXSljzMYF38KG5Tqe?= =?us-ascii?Q?j76hZeZhuPVzrEbpttkVkoxCGTPf4Z4G+2GPxgP7DPs871FsF4ADnTOJrSQP?= =?us-ascii?Q?p53k8cmuKIFAo6OVS1BCf103Pe+ZiqnG8cUa0XW2GfPbDBC97rJgAUjrXhq/?= =?us-ascii?Q?4P3qGBPbZv7CwKJUzpwcohLht++NhHNxj+4wnWSZRgKQ7nyJPR0QEWVvYx2M?= =?us-ascii?Q?gVh6PIyILlobGM2KXx3q2EG+hBOLN7yXTCnejSHI7X8Ep4uuQwQbs2matV82?= =?us-ascii?Q?SD7UxUvQvUxKPk8O3KU8Z7CBXwY1MmPg8d9c3fsQgqbXjKJjdE9JciXi46gR?= =?us-ascii?Q?eG3TrYmiU0UCu2nspJQDd8PAPUq2H1DK9H5A6aRLV/41pzMf4MlBH/AgH/cJ?= =?us-ascii?Q?VD2KexlVnjqSaC/rbaFnTZwXOLrvMaqbQwfHByUOBuRTUt/GopUue452RepE?= =?us-ascii?Q?RD6CHgwOfP+2bhHB1GKFaAkpgxN9giV9WepPxWOU2btgS8//pcrPPKkK+Il8?= =?us-ascii?Q?Mqs36pNtKffUxFngw2KlKtUJ/vi8lZuW1XvMa0o34jjokhxfddET9Q0DGv4t?= =?us-ascii?Q?M9m/HYspAnl2UU0AlgBTZlyw9MukqqsPn8F1J9FZX4v4ocx6x8Aao0xpdhss?= =?us-ascii?Q?0l+jBR9yUjXh0j7J27TcWcrmS55gvzabt4T9lDHBy6cdf3eXVZv3Tp4wG6Bl?= =?us-ascii?Q?yzIDc6fcgDr3TYS3/c64QNUeFIwb/V2T?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN3PR01MB9212.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(52116014)(7416014)(366016)(10070799003)(1800799024);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?AXGiL46Oj7DSJw+EpYs43irytXIMsrevHSu1Q/1GIQdVnk3lm7G4EX2wcKIW?= =?us-ascii?Q?+xlAMr2XaFLxysKYBQB7Ax7j5TKXOn8wgVB8SqJmwFQi06td4fCKfcSGywzJ?= =?us-ascii?Q?J6MB5dW6sAh71gT2kuAIOdgP+T+MgT+rliHC/tBLodiytPl34hDwPG+fczMM?= =?us-ascii?Q?fdgPFoofRGJArMx5LituDH94L/OmKASeCqmUejDWdruzEZQWUg9WUsysU/gs?= =?us-ascii?Q?OY7Erf2rQfFbi0Z1g7af2S9DnGPPHGKFUBGpMHkdhyAYICszjWw9LfWYz9eJ?= =?us-ascii?Q?x3/+sVCeaOZIGcCMdPsq0JdFXUqhgaplLvZro1nf57fWiTqFbyDA0jitEU1/?= =?us-ascii?Q?DcnrPjXl499KQlUjOywmxDEWazS5XLwup5swCPFEZdcru7/Bmpwl18GaHl2d?= =?us-ascii?Q?EOEMar9fALFCmnikNidMkXfBH1jsu44sn2QeSthzVl96ks5BMTpMzxqxil2c?= =?us-ascii?Q?V9o1aY55nc/oByuWK/wTu7AiZiMnlaHyHG+SK/kORcGGlLsb9dSdvqa3SdTy?= =?us-ascii?Q?Gn4jXsTv/JScIEvFhIw8r+nYPot0XHyS0hk+x7dzvrK7xI3RG5Ro9k4X2F+h?= =?us-ascii?Q?A2UNnKmblNuLnEp51xUA3w0mzTmAlhh28sUvfPtXJDndeXMUKI+rMWzoZmVg?= =?us-ascii?Q?o+g30iC7uUSVDDIwIVykm6GJfkWWb5wOpqo4NIY93GPhYs+jbPVm70Ng5Sru?= =?us-ascii?Q?WM24OXqHrG/Q63bIj178yrzncw1OEgn0Dcdkl37DRADu2nptmnL1j0MAfGRh?= =?us-ascii?Q?txTkl0qG71TLmmTJjeMBm1rAOMeb5ZOkH0dfOORdykwfVPmstHrtlhrEm12G?= =?us-ascii?Q?xxNWmRvsmfQh9Q/KLSQBf7SwQHwjHvIOOnMpauVz+obeIed3Li/hQ/YO3eAO?= =?us-ascii?Q?5iHy/PZJsstfDsqcn8QGPZ3aJ68zCHTl88vgT8t56VXEak3Ovyg7JMiSctMO?= =?us-ascii?Q?CIZPmmQzB0m8T2x6V31IB2OOJ5y/EjlqhI/Xefaph+LuQ/wIKYRIoPoYqYv/?= =?us-ascii?Q?HRK6anpPLaLFfIUIM0cVDttSzk+hOPsxXpMx6o5Am6iBz8M68ZMqauDQMaBh?= =?us-ascii?Q?K/2BKE+KYUQgRWGuJdOgv0FpE0IibCKWHO5XFLvQLnv55OMfQruvfChZTaU0?= =?us-ascii?Q?aWE0/4R9DubmAFRwke8EF5ENZdT4Fnk8jJbL2JODETxq8LMJV7cSFP+Lejea?= =?us-ascii?Q?MTdGvF78DmqJsGAjTXgqoYC39eWQnvIPJF85QKFXTVfQMDg8/Q2Pm2HNdAa0?= =?us-ascii?Q?oUyzL9r9q9fMOKYeJ4mDslSdoUuwh2kP6vM5raJb/7XtMnGQ268mglY/PFEn?= =?us-ascii?Q?p8lfDUdnpktaSTxLu1LUkrJdvmQFQsNvJAzRoHPWs+9fX6RlBJfwBudF3JtW?= =?us-ascii?Q?zBAo+jtLSCr6pKPG1kccv1Fbp+SoTQuwfLfxRha/ex3BUCJmE0fMebisCLnG?= =?us-ascii?Q?+FtG4QueJTKKVQYtFfRFy5n/vaoeiKWEKghsfvsEi2tDEguOTl7RmVZBbQRj?= =?us-ascii?Q?YBrItPVBJ7njFyhxJ8vj5O4j2Z+gRydYrGbQdMAU9/RC1d8SWAm4DXHmlHdN?= =?us-ascii?Q?J+rS5do6upJlJ4kA6zmbfTH3GF16K+eH+wWPEYzORejnhSxun2oMksONivDu?= =?us-ascii?Q?ZaGTwVPikJ5NbE8JtqV2CRQx4/AWig5Eq1GRnALw1N375ARh7EpuVWmQuMzb?= =?us-ascii?Q?PeBar5aiR3HjtCblizjRUO6uhZY=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 44523f82-b3b1-44ee-e518-08de0cf7581d X-MS-Exchange-CrossTenant-AuthSource: BN3PR01MB9212.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2025 21:02:40.9772 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kxWutPhg0GXS7yHxvYc8NDRLlolu2RkuAv1tg6iRA8NKPtERJmq1u0jrDVX8zp6DGXX//2qRWAfF5qZ+SR32gki394wjRlVYWFpk0q4NZeY/3KfVjabe+sHUrBYcCV8W X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR01MB7813 Content-Type: text/plain; charset="utf-8" Adds functions that aid in compliance with the PCC protocol by checking the command complete flag status. Adds a function that exposes the size of the shared buffer without activating the channel. Adds a function that allows a client to query the number of bytes avaialbel to read in order to preallocate buffers for reading. Signed-off-by: Adam Young --- drivers/mailbox/pcc.c | 129 ++++++++++++++++++++++++++++++++++++++++++ include/acpi/pcc.h | 38 +++++++++++++ 2 files changed, 167 insertions(+) diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c index 978a7b674946..653897d61db5 100644 --- a/drivers/mailbox/pcc.c +++ b/drivers/mailbox/pcc.c @@ -367,6 +367,46 @@ static irqreturn_t pcc_mbox_irq(int irq, void *p) return IRQ_HANDLED; } =20 +static +struct pcc_chan_info *lookup_channel_info(int subspace_id) +{ + struct pcc_chan_info *pchan; + struct mbox_chan *chan; + + if (subspace_id < 0 || subspace_id >=3D pcc_chan_count) + return ERR_PTR(-ENOENT); + + pchan =3D chan_info + subspace_id; + chan =3D pchan->chan.mchan; + if (IS_ERR(chan) || chan->cl) { + pr_err("Channel not found for idx: %d\n", subspace_id); + return ERR_PTR(-EBUSY); + } + return pchan; +} + +/** + * pcc_mbox_buffer_size - PCC clients call this function to + * request the size of the shared buffer in cases + * where requesting the channel would prematurely + * trigger channel activation and message delivery. + * @subspace_id: The PCC Subspace index as parsed in the PCC client + * ACPI package. This is used to lookup the array of PCC + * subspaces as parsed by the PCC Mailbox controller. + * + * Return: The size of the shared buffer. + */ +int pcc_mbox_buffer_size(int index) +{ + struct pcc_chan_info *pchan =3D lookup_channel_info(index); + + if (IS_ERR(pchan)) + return -1; + return pchan->chan.shmem_size; +} +EXPORT_SYMBOL_GPL(pcc_mbox_buffer_size); + + /** * pcc_mbox_request_channel - PCC clients call this function to * request a pointer to their PCC subspace, from which they @@ -437,6 +477,95 @@ void pcc_mbox_free_channel(struct pcc_mbox_chan *pchan) } EXPORT_SYMBOL_GPL(pcc_mbox_free_channel); =20 +/** + * pcc_mbox_query_bytes_available + * + * @pchan pointer to channel associated with buffer + * Return: the number of bytes available to read from the shared buffer + */ +int pcc_mbox_query_bytes_available(struct pcc_mbox_chan *pchan) +{ + struct pcc_extended_header pcc_header; + struct pcc_chan_info *pinfo =3D pchan->mchan->con_priv; + int data_len; + u64 val; + + pcc_chan_reg_read(&pinfo->cmd_complete, &val); + if (val) { + pr_info("%s Buffer not enabled for reading", __func__); + return -1; + } + memcpy_fromio(&pcc_header, pchan->shmem, + sizeof(pcc_header)); + data_len =3D pcc_header.length - sizeof(u32) + sizeof(pcc_header); + return data_len; +} +EXPORT_SYMBOL_GPL(pcc_mbox_query_bytes_available); + +/** + * pcc_mbox_read_from_buffer - Copy bytes from shared buffer into data + * + * @pchan - channel associated with the shared buffer + * @len - number of bytes to read + * @data - pointer to memory in which to write the data from the + * shared buffer + * + * Return: number of bytes read and written into daa + */ +int pcc_mbox_read_from_buffer(struct pcc_mbox_chan *pchan, int len, void *= data) +{ + struct pcc_chan_info *pinfo =3D pchan->mchan->con_priv; + int data_len; + u64 val; + + pcc_chan_reg_read(&pinfo->cmd_complete, &val); + if (val) { + pr_info("%s buffer not enabled for reading", __func__); + return -1; + } + data_len =3D pcc_mbox_query_bytes_available(pchan); + if (len < data_len) + data_len =3D len; + memcpy_fromio(data, pchan->shmem, len); + return len; +} +EXPORT_SYMBOL_GPL(pcc_mbox_read_from_buffer); + +/** + * pcc_mbox_write_to_buffer, copy the contents of the data + * pointer to the shared buffer. Confirms that the command + * flag has been set prior to writing. Data should be a + * properly formatted extended data buffer. + * pcc_mbox_write_to_buffer + * @pchan: channel + * @len: Length of the overall buffer passed in, including the + * Entire header. The length value in the shared buffer header + * Will be calculated from len. + * @data: Client specific data to be written to the shared buffer. + * Return: number of bytes written to the buffer. + */ +int pcc_mbox_write_to_buffer(struct pcc_mbox_chan *pchan, int len, void *d= ata) +{ + struct pcc_extended_header *pcc_header =3D data; + struct mbox_chan *mbox_chan =3D pchan->mchan; + + /* + * The PCC header length includes the command field + * but not the other values from the header. + */ + pcc_header->length =3D len - sizeof(struct pcc_extended_header) + sizeof(= u32); + + if (!pcc_last_tx_done(mbox_chan)) { + pr_info("%s pchan->cmd_complete not set.", __func__); + return 0; + } + memcpy_toio(pchan->shmem, data, len); + + return len; +} +EXPORT_SYMBOL_GPL(pcc_mbox_write_to_buffer); + + /** * pcc_send_data - Called from Mailbox Controller code. Used * here only to ring the channel doorbell. The PCC client diff --git a/include/acpi/pcc.h b/include/acpi/pcc.h index 840bfc95bae3..96a6f85fc1ba 100644 --- a/include/acpi/pcc.h +++ b/include/acpi/pcc.h @@ -19,6 +19,13 @@ struct pcc_mbox_chan { u16 min_turnaround_time; }; =20 +struct pcc_extended_header { + u32 signature; + u32 flags; + u32 length; + u32 command; +}; + /* Generic Communications Channel Shared Memory Region */ #define PCC_SIGNATURE 0x50434300 /* Generic Communications Channel Command Field */ @@ -37,6 +44,17 @@ struct pcc_mbox_chan { extern struct pcc_mbox_chan * pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id); extern void pcc_mbox_free_channel(struct pcc_mbox_chan *chan); +extern +int pcc_mbox_write_to_buffer(struct pcc_mbox_chan *pchan, int len, void *d= ata); +extern +int pcc_mbox_query_bytes_available(struct pcc_mbox_chan *pchan); +extern +int pcc_mbox_read_from_buffer(struct pcc_mbox_chan *pchan, int len, + void *data); +extern +int pcc_mbox_buffer_size(int index); + + #else static inline struct pcc_mbox_chan * pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id) @@ -44,6 +62,26 @@ pcc_mbox_request_channel(struct mbox_client *cl, int sub= space_id) return ERR_PTR(-ENODEV); } static inline void pcc_mbox_free_channel(struct pcc_mbox_chan *chan) { } +static inline +int pcc_mbox_write_to_buffer(struct pcc_mbox_chan *pchan, int len, void *d= ata) +{ + return 0; +} +static inline int pcc_mbox_query_bytes_available(struct pcc_mbox_chan *pch= an); +{ + return 0; +} +static inline +int pcc_mbox_read_from_buffer(struct pcc_mbox_chan *pchan, int len, void *= data) +{ + return 0; +} +static inline +int pcc_mbox_buffer_size(int index) +{ + return -1; +} + #endif =20 #endif /* _PCC_H */ --=20 2.43.0 From nobody Sun Dec 14 12:11:04 2025 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11023091.outbound.protection.outlook.com [40.93.196.91]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85D892E6100; Thu, 16 Oct 2025 21:02:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.196.91 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760648569; cv=fail; b=Uj9val6zg4KFoXbv4sHFU9UqKam/EN4GSXq8ZG1Ydtbq/wVuRwTpc6KmnZPDDAJeOoGsV3Jfz/aQzw25sQ/FD0L5cBMUL+eta9XPCqspVWISOiOHt50Y7n9gp+c+qW/R8PkHqH3Rf6TR3NGNxfjcf7qDjNzooTw3jYw9tXA/ses= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760648569; c=relaxed/simple; bh=nuQaR0buCFjIVK7S4s1+7z4Tc7sihJdAhDMKiqzeMVo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=lITF0koYoQE2Sux6cHQtN4C+QWlmJ15cBQD3xbj6uZ/vtccYsbahwtTGAs9k82kSzleI8QCqwGF7l5J9Z+o+x0Oh0SrWoJnmxt2Q9/h9RyEOwVDarxLEMWVyveYD/zQfXho+MMiKhTa1x9mpnTHYBcKJ3rvYcbbBY3WGa8wZBoY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=os.amperecomputing.com; spf=pass smtp.mailfrom=os.amperecomputing.com; dkim=pass (1024-bit key) header.d=os.amperecomputing.com header.i=@os.amperecomputing.com header.b=ktGuzpys; arc=fail smtp.client-ip=40.93.196.91 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=os.amperecomputing.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=os.amperecomputing.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=os.amperecomputing.com header.i=@os.amperecomputing.com header.b="ktGuzpys" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sxUv6Q9M4Viw2WgFpc8Kcjblg8cvVZsf1OQi3OjL+JiDFFvOLu9FKQzZcvXUEx6ISBa0FGqNV1I9vXleE9IDC0BeIy97SmLCuW8Eo9gM6ui29O5gLTnI2v0WI/QhwAGJEgc/LkjzN5eH1GhXQHCoZavdUA5M0oMSKRDoRzGcItxDFtxtNHZfWTJ/NIJTousVZCBlKIArnGzl8OhzXmMeAvFnI+YCYH6VrYjFpulnVDGwAfLOIs87xN6DzCVbEKjeEI/7rxNjvJ2QU3KRGHQxbXWi8fWKLE+vPZhhKpwdb9cO0NdM2/oV8Jxdt4PTP6VyIcNXHOCBLtZJoXLKQ8cTew== 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=KSzn7FZJCnOWKB5F0fd5ql/t+eQo2DrwImXplRPd5QU=; b=KeYoTcVOhPEZOONBgqePcPsVQl14lk3VjPe2W/rv1aBwKHUWjGbU9uJ7J8KIVZkNHFCQ255uKfhiwzz87YvrTNEKzhmgGoQsleMkmcy4e+ik5P4eI5RQVCiDj4to1HyaanWL4LiMsf85u1szeOvWbtCy6aLCLIbq4v/85lRbWMn3Hx8ALoEo5v02RsHX0h0N2rzZxTEXQPTG8uM475Y96fGBzhfjTRgd7VQjt8uj7jRsN4S0BhWo8Eg2DhfhyW57z7k3GKBRqh/Lz1fNh/QGHY7Mj/wQYYM2sqlyexJpcSiyVVsIqUvApmlD+VYnbnwtMQ7PYYuXYh2E/t0MYN//Xw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KSzn7FZJCnOWKB5F0fd5ql/t+eQo2DrwImXplRPd5QU=; b=ktGuzpys+veybQrxGwK0ccciGHrXESkEykC7AVjT8tPcrXESdyUl38IhmAOUoznFfZkayGYP6QN0+diPL50we7jKQL+0YaomK8QBPFuSLyTdIUeH/lWtFajXbwgG7c+pitYKDwrqohdF8REti8xkzXXtuuEsk+AJ/OZTbsWoOmc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from BN3PR01MB9212.prod.exchangelabs.com (2603:10b6:408:2cb::8) by LV2PR01MB7813.prod.exchangelabs.com (2603:10b6:408:171::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9228.13; Thu, 16 Oct 2025 21:02:45 +0000 Received: from BN3PR01MB9212.prod.exchangelabs.com ([fe80::3513:ad6e:208c:5dbd]) by BN3PR01MB9212.prod.exchangelabs.com ([fe80::3513:ad6e:208c:5dbd%3]) with mapi id 15.20.9228.009; Thu, 16 Oct 2025 21:02:45 +0000 From: Adam Young To: Jeremy Kerr , Matt Johnston , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Sudeep Holla , Jonathan Cameron , Huisong Li Subject: [PATCH v30 3/3] mctp pcc: Implement MCTP over PCC Transport Date: Thu, 16 Oct 2025 17:02:21 -0400 Message-ID: <20251016210225.612639-4-admiyo@os.amperecomputing.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251016210225.612639-1-admiyo@os.amperecomputing.com> References: <20251016210225.612639-1-admiyo@os.amperecomputing.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CY5PR15CA0200.namprd15.prod.outlook.com (2603:10b6:930:82::22) To BN3PR01MB9212.prod.exchangelabs.com (2603:10b6:408:2cb::8) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PR01MB9212:EE_|LV2PR01MB7813:EE_ X-MS-Office365-Filtering-Correlation-Id: a5aa5864-3d4c-44f1-3c00-08de0cf75ac3 X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|7416014|366016|10070799003|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q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DYRGPNhD/3r8o4HcB0R?= =?us-ascii?Q?PGEOZd4R+tLLGo/pinz1hLLGsaPBaCnO+FLLhuE3NcnSPP5ZXBMOtl+pzjeP?= =?us-ascii?Q?xH5eHh2SnwjNWKMYnIG51+N2+scHx03jccANIXr4WOcCYMhnIOxR/20Xu80b?= =?us-ascii?Q?nFWtqbSreYVKlATgPh1EICkgauql5JbDmB2G7zTSsHJZ7rTovlOyEgLdJTVr?= =?us-ascii?Q?MRymGIGZPEOllP/J5mMbhTW08DIkjiVj17QId1lE7UBvdGjzp2pWgDtU1JKS?= =?us-ascii?Q?a9af0wJte2VPX/c0F2+3qVQ2ONfg80RUqbv5Jiw9gC+KqyFSUfl2SWpLlE+m?= =?us-ascii?Q?WMIlNG5ucj31P0Bq2RZM9gk/XPVGOOhQxiBky3c/YuvVUSvvqLbDXXgnedsm?= =?us-ascii?Q?668tuFaTdnhD6OMGCHNm9pCBghWs2mS/w86w/UM8WLKuxHr6sNgJOZNM+cNR?= =?us-ascii?Q?HZG7QJG2OisqxOFeBJSU/igP+BMlRx1SNnpxA18aocFofnLPWggxtYLhu+xx?= =?us-ascii?Q?IQ05PLF0EgtcrE7+iopJSwar+CIXiUMlBhjI5m6+4ubBypWwXHKHs9h7Rlwh?= =?us-ascii?Q?GKQPA3ofnT+vWWiQR6G9Judlfn+tkXJRaADi6UR75BBQWwJHB57Jkw=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN3PR01MB9212.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(52116014)(7416014)(366016)(10070799003)(1800799024);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?c2BwDEAaOncPfqG2GVQq0Fk/rYOLogyKMgFrp5jOWfriUXPrGQ/H/VViVlD4?= =?us-ascii?Q?zNFV5kZ5u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3T5SO5/xl5?= =?us-ascii?Q?Kmh5K7SWjSxQQVUfbg9HaZpV5EOvvB9jakrqqUCwHbCYaVbA15EPxM00suyp?= =?us-ascii?Q?Y6f3JjfCT0golyld4oVFDBbQvogh0PYoC3+y0golW469OG0UgbJYGI/cJkel?= =?us-ascii?Q?FteQLX/bYr7wmeoMojlqqRFDRwrbMc0Qp5n7fm9pLLYeszxBVO1R2aYpDwXA?= =?us-ascii?Q?khsSFgUfyAaV/pl/Urj9GdrT7oLEkkMgf6thEMOEy3tl41NyElibYgPPrZ4v?= =?us-ascii?Q?byYoMqxAjee6saq3XRP9O1FMuiD5+Z5UDUvecninHclajrVIdxNnuyyJ9NIz?= =?us-ascii?Q?2NtirYSKvq/cg7KN5fC40Es4FKeyufAoApr+VWwWEPAXUhRBdVnqGq3FyiRt?= =?us-ascii?Q?DNq6QnDw2YabvkZs5lmvikhERy9L9vxa32Qc2ognCXLV+yx8gdgrb/tBUkVS?= =?us-ascii?Q?VfMqo1x08z3JyP95Uwc+kxmjyLMNiCLfLyhPi++rWRZfryGgV+4cEFR6tBn9?= =?us-ascii?Q?3z+PEeiO6/qFCL9CmAPGqwpuJS6/qR79AXZ68dMOKZraJS6/kYt7BoHqao1M?= =?us-ascii?Q?cS1SR37CmSvuICbX3fUsG8lZEV7j90/FLEM83mmYLiX6MOypd6YQC4I3DbPY?= =?us-ascii?Q?f7/LE0Ksi7MNPoQyeGE7rHiXPouTxsSL0c6srvWXvHBXY0CqynMvoAS3G8Lm?= =?us-ascii?Q?q1yrERA+dNG8zqOMfUxuGE71QgtAqqC65hBRDjLj4sP1x5ZDXvqBcdl1oL4n?= =?us-ascii?Q?dC2kuTc252uvwHURozS3Ez3mYpw=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: a5aa5864-3d4c-44f1-3c00-08de0cf75ac3 X-MS-Exchange-CrossTenant-AuthSource: BN3PR01MB9212.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2025 21:02:45.4312 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mJ1kB9z61zV9ynapjG2E2JXt+4ynqqCFc3eVRLEdDY2jF38zsRikCaLwSazowmX2me82AXqJKMjK8P3dvZwFKVaWzeVqN3zr13ENearUIeJ7u9etUk7Nf1Ae9ghsBndH X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR01MB7813 Content-Type: text/plain; charset="utf-8" Implementation of network driver for Management Component Transport Protocol(MCTP) over Platform Communication Channel(PCC) DMTF DSP:0292 https://www.dmtf.org/sites/default/files/standards/documents/\ DSP0292_1.0.0WIP50.pdf MCTP devices are specified via ACPI by entries in DSDT/SSDT and reference channels specified in the PCCT. Messages are sent on a type 3 and received on a type 4 channel. Communication with other devices use the PCC based doorbell mechanism; a shared memory segment with a corresponding interrupt and a memory register used to trigger remote interrupts. This driver takes advantage of PCC mailbox shared functions management. Unlike the existing Type 2 drivers, the mssg parameter is actively used. The data section of the struct sk_buff that contains the outgoing packet is sent to the mailbox, already properly formatted as a PCC exctended message. The driver makes use of the pcc mailbox buffer management helpers. These allow the network driver to use common code for the reading and wrting from the shared memory buffer to the mailbox driver, attempting to get a single implementation of the PCC protocol for Type3/4. If the mailbox ring buffer is full, the driver stops the incoming packet queues until a message has been sent, freeing space in the ring buffer. When the Type 3 channel outbox receives a txdone response interrupt, it consumes the outgoing sk_buff, allowing it to be freed. Bringing up an interface creates the channel between the network driver and the mailbox driver. This enables communication with the remote endpoint, to include the receipt of new messages. Bringing down an interface removes the channel, and no new messages can be delivered. Stopping the interface also frees any packets that are cached in the mailbox ringbuffer. Signed-off-by: Adam Young --- MAINTAINERS | 5 + drivers/net/mctp/Kconfig | 13 ++ drivers/net/mctp/Makefile | 1 + drivers/net/mctp/mctp-pcc.c | 319 ++++++++++++++++++++++++++++++++++++ 4 files changed, 338 insertions(+) create mode 100644 drivers/net/mctp/mctp-pcc.c diff --git a/MAINTAINERS b/MAINTAINERS index 46126ce2f968..e1497608a05d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14915,6 +14915,11 @@ F: include/net/mctpdevice.h F: include/net/netns/mctp.h F: net/mctp/ =20 +MANAGEMENT COMPONENT TRANSPORT PROTOCOL (MCTP) over PCC (MCTP-PCC) Driver +M: Adam Young +S: Maintained +F: drivers/net/mctp/mctp-pcc.c + MAPLE TREE M: Liam R. Howlett R: Alice Ryhl diff --git a/drivers/net/mctp/Kconfig b/drivers/net/mctp/Kconfig index cf325ab0b1ef..77cd4091050c 100644 --- a/drivers/net/mctp/Kconfig +++ b/drivers/net/mctp/Kconfig @@ -47,6 +47,19 @@ config MCTP_TRANSPORT_I3C A MCTP protocol network device is created for each I3C bus having a "mctp-controller" devicetree property. =20 +config MCTP_TRANSPORT_PCC + tristate "MCTP PCC transport" + depends on ACPI + help + Provides a driver to access MCTP devices over PCC transport, + A MCTP protocol network device is created via ACPI for each + entry in the DSDT/SSDT that matches the identifier. The Platform + communication channels are selected from the corresponding + entries in the PCCT. + + Say y here if you need to connect to MCTP endpoints over PCC. To + compile as a module, use m; the module will be called mctp-pcc. + config MCTP_TRANSPORT_USB tristate "MCTP USB transport" depends on USB diff --git a/drivers/net/mctp/Makefile b/drivers/net/mctp/Makefile index c36006849a1e..0a591299ffa9 100644 --- a/drivers/net/mctp/Makefile +++ b/drivers/net/mctp/Makefile @@ -1,4 +1,5 @@ obj-$(CONFIG_MCTP_SERIAL) +=3D mctp-serial.o obj-$(CONFIG_MCTP_TRANSPORT_I2C) +=3D mctp-i2c.o obj-$(CONFIG_MCTP_TRANSPORT_I3C) +=3D mctp-i3c.o +obj-$(CONFIG_MCTP_TRANSPORT_PCC) +=3D mctp-pcc.o obj-$(CONFIG_MCTP_TRANSPORT_USB) +=3D mctp-usb.o diff --git a/drivers/net/mctp/mctp-pcc.c b/drivers/net/mctp/mctp-pcc.c new file mode 100644 index 000000000000..927a525c1121 --- /dev/null +++ b/drivers/net/mctp/mctp-pcc.c @@ -0,0 +1,319 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * mctp-pcc.c - Driver for MCTP over PCC. + * Copyright (c) 2024-2025, Ampere Computing LLC + * + */ + +/* Implementation of MCTP over PCC DMTF Specification DSP0256 + * https://www.dmtf.org/sites/default/files/standards/documents/DSP0292_1.= 0.0WIP50.pdf + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define MCTP_SIGNATURE "MCTP" +#define MCTP_SIGNATURE_LENGTH (sizeof(MCTP_SIGNATURE) - 1) +#define MCTP_MIN_MTU 68 +#define PCC_DWORD_TYPE 0x0c + +struct mctp_pcc_mailbox { + u32 index; + struct pcc_mbox_chan *chan; + struct mbox_client client; +}; + +/* The netdev structure. One of these per PCC adapter. */ +struct mctp_pcc_ndev { + struct net_device *ndev; + struct acpi_device *acpi_device; + struct mctp_pcc_mailbox inbox; + struct mctp_pcc_mailbox outbox; +}; + +static void mctp_pcc_client_rx_callback(struct mbox_client *cl, void *mssg) +{ + struct pcc_extended_header pcc_header; + struct mctp_pcc_ndev *mctp_pcc_ndev; + struct mctp_pcc_mailbox *inbox; + struct mctp_skb_cb *cb; + struct sk_buff *skb; + int size; + + mctp_pcc_ndev =3D container_of(cl, struct mctp_pcc_ndev, inbox.client); + inbox =3D &mctp_pcc_ndev->inbox; + size =3D pcc_mbox_query_bytes_available(inbox->chan); + if (size =3D=3D 0) + return; + skb =3D netdev_alloc_skb(mctp_pcc_ndev->ndev, size); + if (!skb) { + dev_dstats_rx_dropped(mctp_pcc_ndev->ndev); + return; + } + skb_put(skb, size); + skb->protocol =3D htons(ETH_P_MCTP); + pcc_mbox_read_from_buffer(inbox->chan, size, skb->data); + dev_dstats_rx_add(mctp_pcc_ndev->ndev, skb->len); + skb_reset_mac_header(skb); + skb_pull(skb, sizeof(pcc_header)); + skb_reset_network_header(skb); + cb =3D __mctp_cb(skb); + cb->halen =3D 0; + netif_rx(skb); +} + +static netdev_tx_t mctp_pcc_tx(struct sk_buff *skb, struct net_device *nde= v) +{ + struct mctp_pcc_ndev *mpnd =3D netdev_priv(ndev); + struct pcc_extended_header *pcc_header; + int len =3D skb->len; + int rc; + + rc =3D skb_cow_head(skb, sizeof(*pcc_header)); + if (rc) { + dev_dstats_tx_dropped(ndev); + kfree_skb(skb); + return NETDEV_TX_OK; + } + + pcc_header =3D skb_push(skb, sizeof(*pcc_header)); + pcc_header->signature =3D PCC_SIGNATURE | mpnd->outbox.index; + pcc_header->flags =3D PCC_CMD_COMPLETION_NOTIFY; + memcpy(&pcc_header->command, MCTP_SIGNATURE, MCTP_SIGNATURE_LENGTH); + pcc_header->length =3D len + MCTP_SIGNATURE_LENGTH; + rc =3D mbox_send_message(mpnd->outbox.chan->mchan, skb); + + if (rc < 0) { + netif_stop_queue(ndev); + return NETDEV_TX_BUSY; + } + + dev_dstats_tx_add(ndev, len); + return NETDEV_TX_OK; +} + +static void mctp_pcc_tx_prepare(struct mbox_client *cl, void *mssg) +{ + struct mctp_pcc_ndev *mctp_pcc_ndev; + struct mctp_pcc_mailbox *outbox; + struct sk_buff *skb =3D mssg; + int len_sent; + + mctp_pcc_ndev =3D container_of(cl, struct mctp_pcc_ndev, outbox.client); + outbox =3D &mctp_pcc_ndev->outbox; + + if (!skb) + return; + + len_sent =3D pcc_mbox_write_to_buffer(outbox->chan, skb->len, skb->data); + if (len_sent =3D=3D 0) + pr_info("packet dropped"); +} + +static void mctp_pcc_tx_done(struct mbox_client *c, void *mssg, int r) +{ + struct mctp_pcc_ndev *mctp_pcc_ndev; + struct mctp_pcc_mailbox *outbox; + struct sk_buff *skb =3D mssg; + + mctp_pcc_ndev =3D container_of(c, struct mctp_pcc_ndev, outbox.client); + outbox =3D container_of(c, struct mctp_pcc_mailbox, client); + if (skb) + dev_consume_skb_any(skb); + netif_wake_queue(mctp_pcc_ndev->ndev); +} + +static int mctp_pcc_ndo_open(struct net_device *ndev) +{ + struct mctp_pcc_ndev *mctp_pcc_ndev =3D netdev_priv(ndev); + struct mctp_pcc_mailbox *outbox, *inbox; + + outbox =3D &mctp_pcc_ndev->outbox; + inbox =3D &mctp_pcc_ndev->inbox; + + outbox->chan =3D pcc_mbox_request_channel(&outbox->client, outbox->index); + if (IS_ERR(outbox->chan)) + return PTR_ERR(outbox->chan); + + inbox->client.rx_callback =3D mctp_pcc_client_rx_callback; + inbox->chan =3D pcc_mbox_request_channel(&inbox->client, inbox->index); + if (IS_ERR(inbox->chan)) { + pcc_mbox_free_channel(outbox->chan); + return PTR_ERR(inbox->chan); + } + return 0; +} + +static int mctp_pcc_ndo_stop(struct net_device *ndev) +{ + struct mctp_pcc_ndev *mctp_pcc_ndev =3D netdev_priv(ndev); + + pcc_mbox_free_channel(mctp_pcc_ndev->outbox.chan); + pcc_mbox_free_channel(mctp_pcc_ndev->inbox.chan); + return 0; +} + +static const struct net_device_ops mctp_pcc_netdev_ops =3D { + .ndo_open =3D mctp_pcc_ndo_open, + .ndo_stop =3D mctp_pcc_ndo_stop, + .ndo_start_xmit =3D mctp_pcc_tx, +}; + +static void mctp_pcc_setup(struct net_device *ndev) +{ + ndev->type =3D ARPHRD_MCTP; + ndev->hard_header_len =3D 0; + ndev->tx_queue_len =3D 0; + ndev->flags =3D IFF_NOARP; + ndev->netdev_ops =3D &mctp_pcc_netdev_ops; + ndev->needs_free_netdev =3D true; + ndev->pcpu_stat_type =3D NETDEV_PCPU_STAT_DSTATS; +} + +struct mctp_pcc_lookup_context { + int index; + u32 inbox_index; + u32 outbox_index; +}; + +static acpi_status lookup_pcct_indices(struct acpi_resource *ares, + void *context) +{ + struct mctp_pcc_lookup_context *luc =3D context; + struct acpi_resource_address32 *addr; + + if (ares->type !=3D PCC_DWORD_TYPE) + return AE_OK; + + addr =3D ACPI_CAST_PTR(struct acpi_resource_address32, &ares->data); + switch (luc->index) { + case 0: + luc->outbox_index =3D addr[0].address.minimum; + break; + case 1: + luc->inbox_index =3D addr[0].address.minimum; + break; + } + luc->index++; + return AE_OK; +} + +static void mctp_cleanup_netdev(void *data) +{ + struct net_device *ndev =3D data; + + mctp_unregister_netdev(ndev); +} + +static int initialize_MTU(struct net_device *ndev) +{ + struct mctp_pcc_ndev *mctp_pcc_ndev =3D netdev_priv(ndev); + struct mctp_pcc_mailbox *outbox; + int mctp_pcc_mtu; + + outbox =3D &mctp_pcc_ndev->outbox; + mctp_pcc_mtu =3D pcc_mbox_buffer_size(outbox->index); + if (mctp_pcc_mtu =3D=3D -1) + return -1; + + mctp_pcc_mtu =3D mctp_pcc_mtu - sizeof(struct pcc_extended_header); + mctp_pcc_ndev =3D netdev_priv(ndev); + ndev->mtu =3D MCTP_MIN_MTU; + ndev->max_mtu =3D mctp_pcc_mtu; + ndev->min_mtu =3D MCTP_MIN_MTU; + + return 0; +} + +static int mctp_pcc_driver_add(struct acpi_device *acpi_dev) +{ + struct mctp_pcc_lookup_context context =3D {0}; + struct mctp_pcc_ndev *mctp_pcc_ndev; + struct device *dev =3D &acpi_dev->dev; + struct net_device *ndev; + acpi_handle dev_handle; + acpi_status status; + char name[32]; + int rc; + + dev_dbg(dev, "Adding mctp_pcc device for HID %s\n", + acpi_device_hid(acpi_dev)); + dev_handle =3D acpi_device_handle(acpi_dev); + status =3D acpi_walk_resources(dev_handle, "_CRS", lookup_pcct_indices, + &context); + if (!ACPI_SUCCESS(status)) { + dev_err(dev, "FAILED to lookup PCC indexes from CRS\n"); + return -EINVAL; + } + + snprintf(name, sizeof(name), "mctppcc%d", context.inbox_index); + ndev =3D alloc_netdev(sizeof(*mctp_pcc_ndev), name, NET_NAME_PREDICTABLE, + mctp_pcc_setup); + if (!ndev) + return -ENOMEM; + + mctp_pcc_ndev =3D netdev_priv(ndev); + + mctp_pcc_ndev->inbox.index =3D context.inbox_index; + mctp_pcc_ndev->inbox.client.dev =3D dev; + mctp_pcc_ndev->outbox.index =3D context.outbox_index; + mctp_pcc_ndev->outbox.client.dev =3D dev; + + mctp_pcc_ndev->outbox.client.tx_prepare =3D mctp_pcc_tx_prepare; + mctp_pcc_ndev->outbox.client.tx_done =3D mctp_pcc_tx_done; + mctp_pcc_ndev->acpi_device =3D acpi_dev; + mctp_pcc_ndev->ndev =3D ndev; + acpi_dev->driver_data =3D mctp_pcc_ndev; + + rc =3D initialize_MTU(ndev); + if (rc) + goto free_netdev; + + rc =3D mctp_register_netdev(ndev, NULL, MCTP_PHYS_BINDING_PCC); + if (rc) + goto free_netdev; + + return devm_add_action_or_reset(dev, mctp_cleanup_netdev, ndev); +free_netdev: + free_netdev(ndev); + return rc; +} + +static const struct acpi_device_id mctp_pcc_device_ids[] =3D { + { "DMT0001" }, + {} +}; + +static struct acpi_driver mctp_pcc_driver =3D { + .name =3D "mctp_pcc", + .class =3D "Unknown", + .ids =3D mctp_pcc_device_ids, + .ops =3D { + .add =3D mctp_pcc_driver_add, + }, +}; + +module_acpi_driver(mctp_pcc_driver); + +MODULE_DEVICE_TABLE(acpi, mctp_pcc_device_ids); + +MODULE_DESCRIPTION("MCTP PCC ACPI device"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Adam Young "); --=20 2.43.0