From nobody Wed Oct 1 23:33:47 2025 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11020143.outbound.protection.outlook.com [52.101.201.143]) (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 23E4B227E95; Thu, 25 Sep 2025 19:00:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.143 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758826840; cv=fail; b=GKKrvDM8HwWzZ0ZUWAOo2eoJusmMsZ3STaszUiCqhIocSuGdyhcLgpPPO/6ZAolIYVlApw7iFSF/Qxer0wHkl/+DCr7KQi2vwS84rGm3uI+ZOZx9+KGzjJHYEUWlj/bE3PzxcshSrEa1NnIqTf6bZLt6QZveZncrszt98eQPr18= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758826840; c=relaxed/simple; bh=cN8DKJLz9d1KY6MBdmnELf8kGoUj7CwC1hb/8UHXo8k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Ph2JI2OAbC1eWqzTV9SWqFMU5sDL9aNOs/Kc6msB1UgcE2wUjm4s3PvIDo0VPShndy4+IU6IvUjDY5WUPtTXJyziwp2K/UaYSASXv++sQ1FsTjS93keO6g04pstnWESr7dOkUCRIObd9Pje8CrSJwNznUCSVC3MslC8HSbDKI2E= 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=ofxrBzYW; arc=fail smtp.client-ip=52.101.201.143 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="ofxrBzYW" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZPzC16rrau/RouaFACiEV+zUH0WOP+3H1do/+/u+iBNHTvs8dyFyMrRNw1VXY9sJy1DWYVJk8gaSxx+88JWZIVvySt6byMrbiv18ovapd3rMONM+K2Q1KfSkctZ4jJ2j1WZHaYhgfKbZ+pV6B1qaiDgpaGWjjKTLEzIsJ+3FQarhzWbnVV6EpgKi0VNJiihLNoOxEY/FQggLADIFfgFlVDmhJ6Yvsvhzpv1MHGKxcLaMETZ9dKe3Mqm0TXRNQGESKl+qTS8Lkv9yIqm3tP4GHZnL8Vob4lEF1HB3RvAjyiayc5D+LNebg/oNeZC1UrKuuHOGjc8IrVrh2VVdiKaVuQ== 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=gZalEeRoZFufC0ht6s19Dnr3xBqJjC6TWx69Y5/sDSA=; b=G867deq+jTI07RAol26sTqf78gITbmub1GpxaEzJY0XZgzFgshLQxICurnZ5JWWC4FaGlvjk5y01MeQwAAX4WgPmBzt65M6/P+vfql4W0V8treBRQSE3lzx01moO9s//1YBG37GbdNOUCVmQCkQ8W17zoZH4rK3YVrNWZ/eUom2o8q3JeY0fZiFslmkhLLHXQx6YZVMCcpUkhnqw4a1dHU2RxCZFgfnNMruDUAUIfggHITHp4hLB6vQRodKGVktS9gSQ4BrUMkpfIXpxkiujg//vzQDFZa3JNjABEygaS21KfshLLzXenkF+nLQOZnGGSoxYrXDpa28mtahw1rBPpA== 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=gZalEeRoZFufC0ht6s19Dnr3xBqJjC6TWx69Y5/sDSA=; b=ofxrBzYWasloLwG8n5UKK3xeUg6sLXSKUsc/4cbmZnADAYXbt0vcE4K8T+gJeYbWSEmD9XIUitunMp4U9TxUidHMS8+d8qH+A+JzY63/tt13GzMcxMfdu9/23jcSG7r9qjdVYw5Ol5ykRBwRSXzZ2XX99MPjDJ/toa9Jv7b1TIk= 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 SJ0PR01MB6160.prod.exchangelabs.com (2603:10b6:a03:2a1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9160.11; Thu, 25 Sep 2025 19:00: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.9160.008; Thu, 25 Sep 2025 19:00:37 +0000 From: Adam Young To: 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 , Sudeep Holla , Jonathan Cameron , Huisong Li Subject: [PATCH net-next v29 1/3] mailbox: add callback function for rx buffer allocation Date: Thu, 25 Sep 2025 15:00:24 -0400 Message-ID: <20250925190027.147405-2-admiyo@os.amperecomputing.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250925190027.147405-1-admiyo@os.amperecomputing.com> References: <20250925190027.147405-1-admiyo@os.amperecomputing.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CYXPR03CA0015.namprd03.prod.outlook.com (2603:10b6:930:d0::10) 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_|SJ0PR01MB6160:EE_ X-MS-Office365-Filtering-Correlation-Id: 5df81f8b-c908-46ca-c550-08ddfc65d00c X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|52116014|376014|7416014|1800799024|10070799003; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?48faFeHYKhFkTXQA2ooFVdj9eyC9x9Y6swap+cM7YxWFKNaKBFZIacwZaq77?= =?us-ascii?Q?7vaacAcqpa7fiS1pw9QQxq6ZBxRhEnck2wpe+OxgN5aVUYhIZ25UDq382Llr?= =?us-ascii?Q?RBwL9rc9r9vNpyx8IEmIfAC0joE2bGGS7SvomKhao+Zvcx+ScawSDFKmSfvE?= =?us-ascii?Q?jqrWwfS2kwRH6qMrauHK4F1EgH9LD2c2qAmnXW33qCMjLuN+fhAEK2cJ3so8?= =?us-ascii?Q?k0tWj/liJheb8beNSc9ep+gtKUvJCioAUOXKweCpte6tqSJY+himYGLBOmZ/?= =?us-ascii?Q?2VcXuHxesBK9FvZevxck6upUReKmrx2JRGk43OvTVQ8+B0Oymtyjl3BPMumc?= =?us-ascii?Q?bWbvclnuk2287luBbSoeqjFs+UQea0jw501zO2jxN5tbI+qAAknv8K2bt6pV?= =?us-ascii?Q?WiCT9pnVgo1U6pITrgEmD4sv4v5TlZhsffIyDA9AbeypUZ6NsCkh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9Rf3D9kkRZALMzxidNd+h+twHHQh2U6onjm3R3yQu?= =?us-ascii?Q?16j/oolT+6FKINeksmWOXmZgeCKVYOuo1YbUFvq3nJEHu2PCfxAOA92YkBaP?= =?us-ascii?Q?9VEtV6EBhpz/M8mURtOFZ+XGG9jr3cog?= 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)(366016)(52116014)(376014)(7416014)(1800799024)(10070799003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?J8hUuxylvEGNwGuHgFcRRbwe+8kl9qKVTlQc+9bIIsEGgWknxzHw7bUXhzfR?= =?us-ascii?Q?CB+XfbPu2W4HcEsGWOa8XfcL4h3DBKiZGR4xTI3pbO5kjlE1cCw7z3NMdCM7?= =?us-ascii?Q?vbMzUWAKLAB8tK8nTsU0CyFc/IES81w0LEigGjykoMRzFGNGdcUjgByFkpiz?= =?us-ascii?Q?Ws/AgzxzHY1lJWMaSbHPWG3Lu8RfsLdEme/PhKXV7w8Enxd2gmCsNDXYw3qH?= =?us-ascii?Q?2s7JzIFHKIS5aWXWjb+G94PuGeGfm+POR4OF+MXTP1zS+eYA7tsLtWxts7ck?= =?us-ascii?Q?78qJvidbFSaJchb4ASruAmzQoVOcGc5lbzFMvlHii4b45KtaXaS4fiT6JmEa?= =?us-ascii?Q?faw7ywCnh4Molne993ZKsmeSv3VPB3BzYzFNoxBQhZglZwsOmSOaNDTTGGas?= =?us-ascii?Q?srWk4tSkoOJnQK0HIoQ6LWQB5DWQTBNSvx0IY+23+fmS1oEmMFuD8uVbVUPk?= =?us-ascii?Q?sjuR+HUYcKyNQQSpDo8XQN1vbMxKdOkFNxVu8ySeKwOrqg3HigTVs3ejG04f?= =?us-ascii?Q?o3WHwwHlGGKZ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-ascii?Q?R+nByJjP00CqgcHfQM/NQS9GYwgMVph27SSN72AgB9n65FkHJsMa/B0SGXpe?= =?us-ascii?Q?Oqgc6oq9RErijGjSRxsIMiJKC/z+4UFr/QBiTsm3/+vkcxSmQOOeHaqry7l5?= =?us-ascii?Q?UvgO1FztlfVLch3PFAkcQUju1U9I2mR72R3RptNiwWaUjqK29BDCjS5ioXUo?= =?us-ascii?Q?I7juqshes2zjx26nvKdHPxy9IuaGoynUBvpglwtU0muydnBfbiyqtH+VgRL8?= =?us-ascii?Q?FCod19hQv3FpnIxF0OEJC5tgJvQ=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5df81f8b-c908-46ca-c550-08ddfc65d00c X-MS-Exchange-CrossTenant-AuthSource: BN3PR01MB9212.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Sep 2025 19:00:37.0577 (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: 3lsOleQ22gcQDNViFKQbzE15RfGW9xz5UiiIBwAKuagRzHCT/CGNvgEnA8xIISoJ7lZDhxuGIrf27jvSod6YsekQhJ2rR7H29GpbcK5BGSLBsAgxPnTm+hkf33Wi9J70 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR01MB6160 Content-Type: text/plain; charset="utf-8" Allows the mailbox client to specify how to allocate the memory that the mailbox controller uses to send the message to the client. In the case of a network driver, the message should be allocated as a struct sk_buff allocated and managed by the network subsystem. The two parameters passed back from the callback represent the sk_buff itself and the data section inside the skbuff where the message gets written. For simpler cases where the client kmallocs a buffer or returns static memory, both pointers should point to the same value. Signed-off-by: Adam Young --- include/linux/mailbox_client.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/mailbox_client.h b/include/linux/mailbox_client.h index c6eea9afb943..901184d0515e 100644 --- a/include/linux/mailbox_client.h +++ b/include/linux/mailbox_client.h @@ -21,6 +21,12 @@ struct mbox_chan; * @knows_txdone: If the client could run the TX state machine. Usually * if the client receives some ACK packet for transmission. * Unused if the controller already has TX_Done/RTR IRQ. + * @rx_alloc Optional callback that allows the driver + * to allocate the memory used for receiving + * messages. The handle parameter is the value to return + * to the client,buffer is the location the mailbox should + * write to, and size it the size of the buffer to allocate. + * inside the buffer where the mailbox should write the data. * @rx_callback: Atomic callback to provide client the data received * @tx_prepare: Atomic callback to ask client to prepare the payload * before initiating the transmission if required. @@ -32,6 +38,7 @@ struct mbox_client { unsigned long tx_tout; bool knows_txdone; =20 + void (*rx_alloc)(struct mbox_client *cl, void **handle, void **buffer, in= t size); void (*rx_callback)(struct mbox_client *cl, void *mssg); void (*tx_prepare)(struct mbox_client *cl, void *mssg); void (*tx_done)(struct mbox_client *cl, void *mssg, int r); --=20 2.43.0 From nobody Wed Oct 1 23:33:47 2025 Received: from DM5PR21CU001.outbound.protection.outlook.com (mail-centralusazon11021090.outbound.protection.outlook.com [52.101.62.90]) (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 1202621B9F1; Thu, 25 Sep 2025 19:00:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.62.90 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758826844; cv=fail; b=XSHH17WMJvmhMEnoVU1DN4GOqs7v/QEjwIPFqI1uzg5nsHyZ79edCTYvkbKGMu+7GZaK3nRHvYMB8kAFFLe7RFdTVDS6LTMMIEyJxpP10tsxKum4sARVOiswiTASVgQp1pa5GcqzHz2ZL1dqY1rUBDgzuCWPA4rf+OSy6/i5HlY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758826844; c=relaxed/simple; bh=ZV3xG33PVbtBV/O4yxf9TiGMvblkV5xTaG1TH84rjDo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=KdROUmaGO/BjEFBdfh2XGc4z4FCFlOW/jweCFP53uK6kCXgy+N7wgV8iy+3zGZjzVXAW0hAqH9qgZEmt77m2FIvrJ0NfNo5bKPo616nMb/s3D6bOJW5s4AEGSkbTtOUZqyKTT3WF3tCljnjYOtgz4OYBVzD+TGhM8yYHZ6VwWkQ= 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=dYCECRRx; arc=fail smtp.client-ip=52.101.62.90 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="dYCECRRx" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jSj7NBWGYiljZ6Ujl6wSLLuDLSkgC/Ibw/mD9lK/9dUIebaUoBfpBcEo8rcKn/Z6ohovep9dGnIt61oAxKmGaY99RLpZwRTtFyUnZbb3FPPkGWTUutKjDJmRX+mJBxWkPsdXDRStGCjxdgnEjY7NY2/BqNMZXOA9YQ2XjGqPJVT78nc6ZJf8sugaw2W1m+/rtXz27RAIyhpuaFq3jcKuKtgwSfQP/0TCLzuCW1lOSUDSZHZYkGnc+UUzCnrYv9wl6lRyB4ndcsTK+z9EkSr1qN7pOosQ/GSiwmP5pSORpYAUnlHva83CU2rTrh726dxNXcfU/Fszo+LpfjJde+woOw== 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=jycDfBGlCZFxhjLBUZd4Ey+3i9OnuuWO7p+tq/6qt+8=; b=Tpk2nB3d4VLbtRWXGVQPkiKCPo3RwUI40d8vV/ZiaASAyeXLh6Xgya/DcIP2ElRXFyjuaWoiGJ/hN6DyLa9p9tHQ087JspgN64jENt2mymEDlBPah1PwVk1PRGr7atHi7rmkoi7ZZcNrPTlpUc4Vid9357Ie4Wtp33oubl4aPNRZ8Ggk6vV+lIH8uavEiLCUgcjZFuT2HjGRA7rVPFkKXOjiStR+op0A3akkRH+Pc3/cKbb3lrhXGJxQQ2axEUnPcIyVr1W77E8qaOa4Os4B+FV4b2PqWKJG4IOvszzFtxb9nRFHVOCdv8+IU0f+3OVtJeFunv1lJlH70JTxM+CCvw== 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=jycDfBGlCZFxhjLBUZd4Ey+3i9OnuuWO7p+tq/6qt+8=; b=dYCECRRxtm4asbqXXDBqsXvhJxcnE28C/1QhcUppSN59T9VoZe9tpfaHPRGWl9CUb0i0igAMQ3zKV2TS32/GE1a/+HKmR3CTbz2lhDjKVtfExrCd9H03BppwxQDhjR3oiH6oSUmZ9vS3NKq+GmAItiFt5MqGzqQszw8iw7mhBGk= 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 SJ0PR01MB6160.prod.exchangelabs.com (2603:10b6:a03:2a1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9160.11; Thu, 25 Sep 2025 19:00:40 +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.9160.008; Thu, 25 Sep 2025 19:00:40 +0000 From: Adam Young To: Sudeep Holla , Jassi Brar , "Rafael J. Wysocki" , Robert Moore , Len Brown 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 net-next v29 2/3] mailbox/pcc: use mailbox-api level rx_alloc callback Date: Thu, 25 Sep 2025 15:00:25 -0400 Message-ID: <20250925190027.147405-3-admiyo@os.amperecomputing.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250925190027.147405-1-admiyo@os.amperecomputing.com> References: <20250925190027.147405-1-admiyo@os.amperecomputing.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CY8PR19CA0019.namprd19.prod.outlook.com (2603:10b6:930:44::28) 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_|SJ0PR01MB6160:EE_ X-MS-Office365-Filtering-Correlation-Id: 04dffc28-02da-47ec-70bd-08ddfc65d208 X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|52116014|376014|7416014|1800799024|10070799003; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?aeJcoRszJiJieZGMl8zmyvteUm4k64scg/lh5+4fvICE7PoUTo0e5hNrQkVJ?= =?us-ascii?Q?9Z6OhuFF38mil/WpyUo4RnOaNdf0gbXHyV+KOsOZA+rUpMjrTxMm6oenuT1u?= =?us-ascii?Q?f8eeDPpztqtT2WGcvEv68tk+EXqorSS9K5mxKjxL4FiKTCNt8DvXiq8IGZAY?= =?us-ascii?Q?fqFfiE7G7Bog8YFrrKPU7GW++pbYe5B+Ai8aYScqHjKgheXzLwxX2YcKNQyY?= =?us-ascii?Q?qPs2+EZQw640K9IGLl4TbE/kenNcF0HzJt1silKROb/ds5jskcXSYJUixhGI?= =?us-ascii?Q?TuIdpiFeciL400aNcYoVh6Vsla4ZBztgMTT+4lh2ahiwcVS9Y5JilfSww0O6?= =?us-ascii?Q?a87fQoD308LBR7QDxLyRZn/osnlvY9tPhDVXGDY94tE8wmGI+oqpjtdULa0I?= =?us-ascii?Q?VdU4tLxf8a9/4FHR0fGyxgcKyAyO1iMbo2znjNBYs/4Ffc0sOAR6FPDbwtzc?= =?us-ascii?Q?ftKfPpvpwXuYr/likhC/xfT0zwXJccHydenN7zIHsIBebsWrHglgEveFb98c?= =?us-ascii?Q?nNWNDp/QlLowCd4mK2RgxmY1sVDPulExTsrv/yKDjK48GHRFwe85NxvNe8Cy?= =?us-ascii?Q?WdStfqi07idPUbxXf/Qw4/k2nRbch5ekRDqlH8R2rVfbJRoEEjluGZxD9ju4?= =?us-ascii?Q?vONnCZAMvWFZgqxnUT+vaZGg+cAW5e+KqMby58/5MpJAtQGnNu2ChE3fvOJC?= =?us-ascii?Q?kJmOfMr1JQGFLgWUOB2poVCOvOW0d8MeQMvndXykkN5Ih1MS70UdO0q7AZ4X?= =?us-ascii?Q?CeCT5CoHKY96jOwRkAMasvIkEZpiHFCyMZyXKaGn5r/BmWPfTvJq7tXNQ55V?= =?us-ascii?Q?oaM96GR4yiYzSHdjUyMrjOS7xofpMSXKlvz5st60Kd10FzNsGa0JeN7H0OPK?= =?us-ascii?Q?6QBA3JNzpB80HBwD/Vyg+5UQ9J5SbYrPu5NlyWoG6ozxL0wp/woklGXsubsp?= =?us-ascii?Q?mU9voJIVpWTvrGcGYpAzEljpeFjmqncBFYalOn1Lxhq80sgQ84OYtgQwNhZy?= =?us-ascii?Q?jmKDBQi/++wWZrZJPKM8ajzqk7wq1QwvPrUTE0tMgS8SAzJXGu5e4B8uoSNK?= =?us-ascii?Q?RSVGxOHKv/+XPtQTuRFGnreSV4jxc3wU4OztMjWJPdufQddQOqxv5E4//uAV?= =?us-ascii?Q?AAap2kkcJ6iU8Y43bn4Bp5KwP7TT06GLMA+saghmKT1gYtQ41kWqSggKJdfC?= =?us-ascii?Q?mCr/mh6T/eJpVuiYoYR2WENz+eZf/2etRiKMyvsiO07CUoamFO7GM9o94Ne3?= =?us-ascii?Q?WIk3cRlHK2WncFS5TOELQM5V0f+fVQ+tp9/5cgZzx2x2cj44hZpt/Q6mAsWa?= =?us-ascii?Q?teXN3HZOcv45vo+LXgO8NOHguvuwvfS8B2OBFB1itTUX3pXJ4A4a3QPycjO7?= =?us-ascii?Q?T5MJBC4MsrnmlubkNlMTaHOSm+Ug5GAEd47xLyyCqqZ0LJZ/UbPWeI2fh/rO?= =?us-ascii?Q?aecyYx/g3fqXVM9D9d5Jv9rLwLoud2DJ?= 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)(366016)(52116014)(376014)(7416014)(1800799024)(10070799003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?GMjcuyo1Z+j5KSAOLb360pvNztwMTEaLulFxbFctSoO+7D5LIF+IVWJPi767?= =?us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JY4e8mqztAVluFITvVvm7M1IsfRqnqNmUlez?= =?us-ascii?Q?ADLd3UtcDX1MZVMSMYGRd49AR0K35HzanmpRSiwBrZBY5fzddwWvDBaPbHbM?= =?us-ascii?Q?Wse7YreESmwXh+DUBoRGm8mGFmeBWsuc6RCNqZQspHtiaj5qbZFHHXWs041t?= =?us-ascii?Q?SfzA/8/sx2axvM+75GN6R7qEzdi9v/3i5fIAo+afQfYnfHcpH6yNnyOoi6av?= =?us-ascii?Q?k9af3ZP4TxF92UlVxVFw0PiWQqMGUkPAlq2mkvvBSPVD1nt39hPLTLa19DPz?= =?us-ascii?Q?gIRk8HaoaefMUHAU1urOCp67iiDikdUTuD9fuBAdz7KkY321GiDE5ZicrlLV?= =?us-ascii?Q?7qdufjigMTJLHZUn5P8GJT7xJCF6R12KoNixUIhPhtOrgM2JLGFnNjMEDxIg?= =?us-ascii?Q?OJ/svuz0OFp6iA1uPKUqZelNM85JIDbrzn/DjdbhoFV4B3qdWw4EmX7KLl56?= =?us-ascii?Q?R7MvCasvJ2iLV7igdzs0M0okRHm66Jd1uldMg2M9M2CNaHtHzIK/TwpnLmqf?= =?us-ascii?Q?GvsFCbeXCb3WPWWOGGZDl0cm1LAGtlMfvunkdtBZWcIb8Oj7Tq7xGXRIDpmF?= =?us-ascii?Q?cGr9580kFjiyzv39czTF6kluICVMdhY362//wDK4W7GF9SWnV2QJOWVSDcQk?= =?us-ascii?Q?gVxJ9pNusk46Rn7shkVcfoLp9kpmWC1wbLITG4RSlAbXnHo+xgr2MyQZcBee?= =?us-ascii?Q?uXO6b9veTSB2oglFeoemFbJG/8UMkZzUMupIZ64QSwmlJkMkTSt/vat0UaS6?= =?us-ascii?Q?OT2domD4sNRsxwMGaOx91EkWmxI=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 04dffc28-02da-47ec-70bd-08ddfc65d208 X-MS-Exchange-CrossTenant-AuthSource: BN3PR01MB9212.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Sep 2025 19:00:40.4688 (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: 4d4ysJXTn7h1jKbAYhcSZxYD92Z/ruxY2B8IJmJow0v8WekIyjXfTBjlDasXtA+eaabFhGVbjA1NehvXJOwgCbbO2Qulqf+j3DRuL95SiIJ6Ur74QAHprotUkBrVupu9 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR01MB6160 Content-Type: text/plain; charset="utf-8" Uses the newly introduced mailbox_api rx_alloc callback. Since this callback is registered in the call to request a channel, it prevents a race condition. Without it, it is impossible to assign the callback before activating the mailbox delivery of messages. This patch also removes the flag pcc_mchan->manage_writes which is not necessary: only type 3 and type 4 subspaces will have their buffers managed by the mailbox. It is not required for the driver to explicitly specify. If a future type 3 or type 4 drivers wishes to manage the buffer directly, they can do so by passing NULL in to mbox_send_message. Signed-off-by: Adam Young --- drivers/mailbox/pcc.c | 16 ++++++++++------ include/acpi/pcc.h | 22 ---------------------- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c index 0a00719b2482..4535cd208b9e 100644 --- a/drivers/mailbox/pcc.c +++ b/drivers/mailbox/pcc.c @@ -309,17 +309,20 @@ static void pcc_chan_acknowledge(struct pcc_chan_info= *pchan) static void *write_response(struct pcc_chan_info *pchan) { struct pcc_header pcc_header; + struct mbox_client *cl; + void *handle; void *buffer; int data_len; =20 + cl =3D pchan->chan.mchan->cl; memcpy_fromio(&pcc_header, pchan->chan.shmem, sizeof(pcc_header)); data_len =3D pcc_header.length - sizeof(u32) + sizeof(struct pcc_header); =20 - buffer =3D pchan->chan.rx_alloc(pchan->chan.mchan->cl, data_len); + cl->rx_alloc(cl, &handle, &buffer, data_len); if (buffer !=3D NULL) memcpy_fromio(buffer, pchan->chan.shmem, data_len); - return buffer; + return handle; } =20 /** @@ -359,7 +362,7 @@ static irqreturn_t pcc_mbox_irq(int irq, void *p) */ pchan->chan_in_use =3D false; =20 - if (pchan->chan.rx_alloc) + if (pchan->chan.mchan->cl->rx_alloc) handle =3D write_response(pchan); =20 if (chan->active_req) { @@ -415,8 +418,6 @@ pcc_mbox_request_channel(struct mbox_client *cl, int su= bspace_id) if (!pcc_mchan->shmem) goto err; =20 - pcc_mchan->manage_writes =3D false; - /* This indicates that the channel is ready to accept messages. * This needs to happen after the channel has registered * its callback. There is no access point to do that in @@ -466,7 +467,10 @@ static int pcc_write_to_buffer(struct mbox_chan *chan,= void *data) struct pcc_mbox_chan *pcc_mbox_chan =3D &pchan->chan; struct pcc_header *pcc_header =3D data; =20 - if (!pchan->chan.manage_writes) + if (data =3D=3D NULL) + return 0; + if (pchan->type < ACPI_PCCT_TYPE_EXT_PCC_MASTER_SUBSPACE || + pchan->type > ACPI_PCCT_TYPE_EXT_PCC_SLAVE_SUBSPACE) return 0; =20 /* The PCC header length includes the command field diff --git a/include/acpi/pcc.h b/include/acpi/pcc.h index 9af3b502f839..5506490e628c 100644 --- a/include/acpi/pcc.h +++ b/include/acpi/pcc.h @@ -17,28 +17,6 @@ struct pcc_mbox_chan { u32 latency; u32 max_access_rate; u16 min_turnaround_time; - - /* Set to true to indicate that the mailbox should manage - * writing the dat to the shared buffer. This differs from - * the case where the drivesr are writing to the buffer and - * using send_data only to ring the doorbell. If this flag - * is set, then the void * data parameter of send_data must - * point to a kernel-memory buffer formatted in accordance with - * the PCC specification. - * - * The active buffer management will include reading the - * notify_on_completion flag, and will then - * call mbox_chan_txdone when the acknowledgment interrupt is - * received. - */ - bool manage_writes; - - /* Optional callback that allows the driver - * to allocate the memory used for receiving - * messages. The return value is the location - * inside the buffer where the mailbox should write the data. - */ - void *(*rx_alloc)(struct mbox_client *cl, int size); }; =20 struct pcc_header { --=20 2.43.0 From nobody Wed Oct 1 23:33:47 2025 Received: from CH5PR02CU005.outbound.protection.outlook.com (mail-northcentralusazon11022077.outbound.protection.outlook.com [40.107.200.77]) (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 2B84C31D726; Thu, 25 Sep 2025 19:00:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.200.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758826851; cv=fail; b=uI4OwQwdtg2JPHBlmwRTKbMUWBY6eio6xhiNshf8SffVvd6oQhtn7xgStMsriPIhXdvPuorPoKTMqyLsloTLKfHgR0qeiyLJcPSrp0DNFIowd/b2RZdZDydUJJ25xgr9Tb3DBwh56wzoJCGAa/9Jpm3EIY2xxdpDdAB0h/shaXU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758826851; c=relaxed/simple; bh=ubE0fvvoQpMs2+FRTkG14g4acM6NSSMyaYHQjA3zDPo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Hh41PU+mRCgwiw7vDI6PHN6TWsBd4IpobahSvfpOmn7oIWmzzAqJSmUv9vpj4qnM/vkRQMPrpQ6oAEG6qTXlqHdvqJsH2G2SfAIFWzjFifRV3cVATHlW/eIeNSNcQeBgXHblpOUzKW4yxRT/L6sF8wld0o1LOlcHjaFjNeEoN54= 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=sD8BGHRU; arc=fail smtp.client-ip=40.107.200.77 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="sD8BGHRU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bud59WOrABjUrvCifHiA/W1FprZgINTk7x0VJhSmO+uqRRNr896bNxvKHehR80ykTlVoLSKX1W9VMC7RR0gmBMvPHKp3o913l1VFZWClf4QU0s3VDeZ6nJ7LnPhB5VI7F/cgaOCpsZGeft9w0zmAgo6pkohFePz39M/v03Y9Qs1t0o54hL2ZqoKsNclRrFZbydyrNtyDkeuHzsOtpoU3jamlMCXE3kiu5i4qstzdp4eA7Et8/E25CcNus9B8c0BJRROGp6ueN8PM8ISXLqbAiiGpPMvMvuG+ZNfxOzMEfV/ir7FpJAK91alCTc8FA7h9+qo5ghqDtKk88wS3XhzeAA== 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=jmehq7ikn65P/zfvJ47JykRJi818kHE2QSVn6ZnL17E=; b=Veb7trkuApW0gYRt4jTjV3QjvALkVKgh5wi2LhJb/C027nMiexLghh9IS72MJoCq6JLc52JzBoiZUUkPOr+xVz6ZQD8DcfRChZNVDb/xg6MycTfuoZLkObrOWagqGnOwddbwqX62DzY/w+okEgrukJ1AUlc6TPDUY7Hs305qhLONZg267j0ul7KIfpKIi6Iu5ksqHFBkC1kjHq2A9oFetzsZdNSceK7b+dV3TutNss8dEvYAu7ruPBRrDoFQJEdDxVaLJY66VS9aXqhN5mGq7giW+KAgFC+ex11wvkChGxQaFTdgMk0RSiLJH1QE+FF8vNxAwkgKPWMAxr0PXzSBrg== 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=jmehq7ikn65P/zfvJ47JykRJi818kHE2QSVn6ZnL17E=; b=sD8BGHRU0tyeFMcffEPQKzEDyPxI5aDvfptK+fIue6cSNw5Z64+x3WhuhsQVhPGLNHc4gshvMlXJ+Ck9qFWlG19XmDjXt6WKl9GvOXctr0fGyIHGxkntr7wBp7GIb7N41QnH5AgoOKTOQk86ixnw1q9Q5BfRrf1WL25u528VU4g= 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 SJ0PR01MB6160.prod.exchangelabs.com (2603:10b6:a03:2a1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9160.11; Thu, 25 Sep 2025 19:00:44 +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.9160.008; Thu, 25 Sep 2025 19:00:44 +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 net-next v29 3/3] mctp pcc: Implement MCTP over PCC Transport Date: Thu, 25 Sep 2025 15:00:26 -0400 Message-ID: <20250925190027.147405-4-admiyo@os.amperecomputing.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250925190027.147405-1-admiyo@os.amperecomputing.com> References: <20250925190027.147405-1-admiyo@os.amperecomputing.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CY5PR15CA0214.namprd15.prod.outlook.com (2603:10b6:930:88::10) 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_|SJ0PR01MB6160:EE_ X-MS-Office365-Filtering-Correlation-Id: 50f15514-cd4c-477f-b65e-08ddfc65d42d X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|52116014|376014|7416014|1800799024|10070799003; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?kuixhSn/eVOlvy80OBAHxwyjSTfXyAnO+JhnLlw0cPLOl0pV9YOnjkNMZGvS?= =?us-ascii?Q?H7/2Mo4HC14hUul0Tb0faXVzvXsq/XOV8yebqYwoBUfjB7WSsgJtZVShQQQw?= =?us-ascii?Q?7PZYtJj5CyyFtHgsyb3PzsUcupi0x6m+nTQHpqyG+Ak5U7gdphg6Q7Af7ZpT?= =?us-ascii?Q?8sro3gC8l3YRDXBRtWgrzyhFcwxELpKTb8lxrr+zmXP51Vd3CL1V4yk8BXoT?= =?us-ascii?Q?T52CIkE9mpffna7UYIwHMNPUt3pVq2w32xsg+ccxDzvdkzJ+Mtx1+pe/OvqX?= =?us-ascii?Q?RObrGJc0oezgzwvj8dJ/dZtHLi44k6uUc/ugityEcMPfF8MFwFpkOpYazatj?= =?us-ascii?Q?tVUdP3GFMmTUByo7ZbU41dPI6fRm4T51JPeufZCE1vOAHleVu64K08KLiyRC?= =?us-ascii?Q?CCAQBtxFo0f1GveDw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-ascii?Q?H6KrEUEcLedRHwxbYtaStKVS0LuDtuZPN3Mkaacg9VEtW1rKqyg6SLZiPBoX?= =?us-ascii?Q?Ys72HN3x6eggev3A6DM1/IASJ9/vOI0ur/Xh2opeCkR3ryKp1w=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)(366016)(52116014)(376014)(7416014)(1800799024)(10070799003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?go2KIF6Vt2nvkm9lzP/s9+sXt8oU9X/QbirGbpGcBIYxi7HjED0c+xnXyqwM?= =?us-ascii?Q?NM4YQLViNIfWmyXgFnuX+KPq+kTYr6xL3jlieQ5n+1/oR4gqG9/FkfPGvP6P?= =?us-ascii?Q?sAPBKMlE2mSBzCrY6faeOyx5UP/JyNyN4XwJQ3pO5bctKRT9rdvldaV6H0qJ?= =?us-ascii?Q?VrnAv9ZIFKSAVC4WCgCQ3zatvz7Ge83YIiZErAB5iL5wnJlrfNvz7uTLwWuG?= =?us-ascii?Q?UnATVuAY7m2/irMIMuCK1T9UH3zi41ozmIZpmH55ZF2tr08/lpuYhA1Uc4JG?= =?us-ascii?Q?EQ1+v7ZkQlLkzlmjcbiWMUgetBvDFplaDBg/tdW7YeIaubl4ohvEt0WyN+aw?= =?us-ascii?Q?3H9KTyfi7ixe7giSZv7/Gn520Wq0BxDBl2CRkCu/6L6/+bdfpmH/R5z9VHYy?= =?us-ascii?Q?OvryBiJZshkD2HU3FgTWowKXObHu78Xb7BcSnJIzLGjjZs7jWLwKCosPdd5j?= =?us-ascii?Q?KdJv9fHiB3hBINovT1zzf10VBjNx4ozWU37QSAb8YUzW6YxVsuvygo6oM+aE?= =?us-ascii?Q?Gvo6B13UDmaAQqPOt7Rb/8eZ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sahDKMloeKYX6PoPP20y9lahrzc1Mbyumf/u7ly7twn+zM7CDsmPrX5JXN?= =?us-ascii?Q?pLAIdS9uuSWNn4I24fIH4xGXmK4xFwbhw/xJ4PsswVtSEi2fMdydlxjE1Me2?= =?us-ascii?Q?dJ0EvX1CdMQM6/v+Dnb7+rKxWOf//eP/PHW5IFWh8kABrR160+YTkR5u1b8c?= =?us-ascii?Q?Kzn0p/Qchj9VTCctzo+yGAuiy2HUZMdZi9VGt6mWen1rOwNA3DvJmmRlIDCC?= =?us-ascii?Q?e4Otz9BwaxDlxRy37UIBnBZqwUw=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50f15514-cd4c-477f-b65e-08ddfc65d42d X-MS-Exchange-CrossTenant-AuthSource: BN3PR01MB9212.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Sep 2025 19:00:43.9848 (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: 3/ZWLKw3+6WgA7x0ujKTxzscICrQyncZtp80gDlpKvFQtSzsqJWpok/phunowm7dmletyhRJbw9QxdyCjTpJ7gp6kuiGEXQVx4tZ950C8W1/m9YhhjQQyItAKz/MKt2n X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR01MB6160 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 buffer management. The data section of the struct sk_buff that contains the outgoing packet is sent to the mailbox, already properly formatted as a PCC message. The driver makes use of the mailbox-api rx_alloc callback. This is responsible for allocating a struct sk_buff that is then passed to the mailbox and used to record the data in the shared buffer. It maintains a list of both outgoing and incoming sk_buffs to match the data buffers. 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 | 341 ++++++++++++++++++++++++++++++++++++ 4 files changed, 360 insertions(+) create mode 100644 drivers/net/mctp/mctp-pcc.c diff --git a/MAINTAINERS b/MAINTAINERS index a8a770714101..f7b9e935543b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14677,6 +14677,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 L: maple-tree@lists.infradead.org diff --git a/drivers/net/mctp/Kconfig b/drivers/net/mctp/Kconfig index cf325ab0b1ef..01855846491b 100644 --- a/drivers/net/mctp/Kconfig +++ b/drivers/net/mctp/Kconfig @@ -57,6 +57,19 @@ config MCTP_TRANSPORT_USB MCTP-over-USB interfaces are peer-to-peer, so each interface represents a physical connection to one remote MCTP endpoint. =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. + endmenu =20 endif diff --git a/drivers/net/mctp/Makefile b/drivers/net/mctp/Makefile index c36006849a1e..2276f148df7c 100644 --- a/drivers/net/mctp/Makefile +++ b/drivers/net/mctp/Makefile @@ -1,3 +1,4 @@ +obj-$(CONFIG_MCTP_TRANSPORT_PCC) +=3D mctp-pcc.o 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 diff --git a/drivers/net/mctp/mctp-pcc.c b/drivers/net/mctp/mctp-pcc.c new file mode 100644 index 000000000000..b525df86e459 --- /dev/null +++ b/drivers/net/mctp/mctp-pcc.c @@ -0,0 +1,341 @@ +// 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; + struct sk_buff_head packets; +}; + +/* 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_rx_alloc(struct mbox_client *c, void **handle, void = **buffer, int size) +{ + struct mctp_pcc_ndev *mctp_pcc_ndev; + struct sk_buff *skb; + + mctp_pcc_ndev =3D container_of(c, struct mctp_pcc_ndev, inbox.client); + + *handle =3D NULL; + *buffer =3D NULL; + + if (size > mctp_pcc_ndev->ndev->mtu) + return; + skb =3D netdev_alloc_skb(mctp_pcc_ndev->ndev, size); + if (!skb) + return; + skb_put(skb, size); + skb->protocol =3D htons(ETH_P_MCTP); + + *buffer =3D skb->data; + *handle =3D skb; +} + +static void mctp_pcc_client_rx_callback(struct mbox_client *c, void *buffe= r) +{ + struct mctp_pcc_ndev *mctp_pcc_ndev; + struct pcc_header pcc_header; + struct sk_buff *skb =3D buffer; + struct mctp_skb_cb *cb; + + mctp_pcc_ndev =3D container_of(c, struct mctp_pcc_ndev, inbox.client); + if (!buffer) { + dev_dstats_rx_dropped(mctp_pcc_ndev->ndev); + return; + } + + if (skb) { + 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 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 NULL; + struct sk_buff *curr_skb; + + mctp_pcc_ndev =3D container_of(c, struct mctp_pcc_ndev, outbox.client); + outbox =3D container_of(c, struct mctp_pcc_mailbox, client); + spin_lock(&outbox->packets.lock); + skb_queue_walk(&outbox->packets, curr_skb) { + if (curr_skb->data =3D=3D mssg) { + skb =3D curr_skb; + __skb_unlink(skb, &outbox->packets); + break; + } + } + spin_unlock(&outbox->packets.lock); + if (skb) + dev_consume_skb_any(skb); + netif_wake_queue(mctp_pcc_ndev->ndev); +} + +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_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; + + skb_queue_head(&mpnd->outbox.packets, skb); + + rc =3D mbox_send_message(mpnd->outbox.chan->mchan, skb->data); + + if (rc < 0) { + netif_stop_queue(ndev); + skb_unlink(skb, &mpnd->outbox.packets); + return NETDEV_TX_BUSY; + } + + dev_dstats_tx_add(ndev, len); + return NETDEV_TX_OK; +} + +static void drain_packets(struct sk_buff_head *list) +{ + struct sk_buff *skb; + + while (!skb_queue_empty(list)) { + skb =3D skb_dequeue(list); + dev_consume_skb_any(skb); + } +} + +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 *out =3D &mctp_pcc_ndev->outbox; + struct mctp_pcc_mailbox *in =3D &mctp_pcc_ndev->inbox; + + out->chan =3D pcc_mbox_request_channel(&out->client, out->index); + if (IS_ERR(out->chan)) + return PTR_ERR(out->chan); + + in->client.rx_alloc =3D mctp_pcc_rx_alloc; + in->client.rx_callback =3D mctp_pcc_client_rx_callback; + in->chan =3D pcc_mbox_request_channel(&in->client, in->index); + if (IS_ERR(in->chan)) { + pcc_mbox_free_channel(out->chan); + return PTR_ERR(in->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); + drain_packets(&mctp_pcc_ndev->outbox.packets); + 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; + outbox->chan =3D pcc_mbox_request_channel(&outbox->client, outbox->index); + mctp_pcc_mtu =3D outbox->chan->shmem_size - sizeof(struct pcc_header); + if (IS_ERR(outbox->chan)) + return PTR_ERR(outbox->chan); + + pcc_mbox_free_channel(mctp_pcc_ndev->outbox.chan); + + 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; + skb_queue_head_init(&mctp_pcc_ndev->outbox.packets); + mctp_pcc_ndev->outbox.client.dev =3D dev; + + 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; + + initialize_MTU(ndev); + + rc =3D mctp_register_netdev(ndev, NULL, MCTP_PHYS_BINDING_PCC); + if (rc) { + free_netdev(ndev); + return rc; + } + return devm_add_action_or_reset(dev, mctp_cleanup_netdev, ndev); +} + +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