From nobody Mon Nov 25 04:25:27 2024 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2126.outbound.protection.outlook.com [40.107.93.126]) (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 159BD1D2796; Tue, 29 Oct 2024 16:54:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.126 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730220871; cv=fail; b=f5WoEbjU5ieShhUZXu0oARMZ7Esc3AyFI/VaBn/EtiVb11i8scOoZoJStdAVdEmg/dMyUmTYEvqhpGWPDsh6Zg4e0LJx1t0BU7c/ytD7Cxr8hCzsKxavxDwHhq87QODKL/+PQ5R/3omyC88KhU9ZeWzyhIirnSgimQci4hRQ0is= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730220871; c=relaxed/simple; bh=rM8S3Rt9A2tri9g7wNjHXB67Mw9y2WM2wTjzgf70mWA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=mF5XZybe+paTL3yTLH68bfxzPLvFRWlc2/Fz0q5EBEWIC2zlU6V2X28FnhUy0D+xCu+pZzOKdCEtmB0IxTeSMEq+rrwaQuXpn1v5/8stBwmo235UWk9KpMtA+qV0vt7GBOv/zNUUisejWYZ2momQpTaWNmI6OOnUi4uAPwPLh/o= 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=BBG+zPBr; arc=fail smtp.client-ip=40.107.93.126 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="BBG+zPBr" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=D+rmvDSZTkl5YPKbq3JKXI/orKlOu0I0GvVwVz7zRGzYaER9sV9ZuyPhiwfwD4BhxbfeTELl9+ZEqxWV/XMTku4P8Za9hHUeGtXK99ii/N4nkhEaevm9Zt5f/JbgVDeBKbdcCV3qPiAWc0iC2XxkWiOb+b5j9tdblbZC/wV1K+H+rkk1fbZiUG3nas9BKH7XvM4fNMjvK9bUwX+TQ3TNV25SBn/k2XY9kyGSl1TGSdzMAR0jZ4J1b3KTSHYbGsjoviUqKtAz+0sYnT2aAKb8VK1y5tOq7x+kLtfLerXb7zQd/mdNsScg53vrPtG0GrnLRJx9HeIpQyee/+ojFveKdw== 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=i8nfq8HajUkLRJWZ7V5EV8+D7uBd7lwnRW3Eqhybg/U=; b=yVgYu5s8JBW9HHLDssRsOGg1NWMHbD2SHm247cxBlWi8GR0dB8D8Tp8T6Akm9/D/YFQ/9bRThO+5nw61STz1T0PZ0QsyUNMc0CgLCfeeaoTenEFevmH5p8t0z8L3QEE58YM7o0B7b27NjajxK+BnGp/29+ultuc+67HnkbcXB4vaHnyV9Am4k3nkpkHjTbS3zRMhdC1aykLVQxVWWqC38UpU9CetrD7a/LBINXhbjI3K4lxDBqn/R6T/YJ5O+0FZcL1CoacqkkhoH1gqvZAM4AswSKMOO1hq8xrC7Cf31xbGBAfx8sjAoTu9g8j3Ds3xDgZ2I3twIMejtQWK39cwvg== 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=i8nfq8HajUkLRJWZ7V5EV8+D7uBd7lwnRW3Eqhybg/U=; b=BBG+zPBr2fwDayH6sqNDF/8ulFZfGFy/st8iJfyo6tL0N3Pl8kswVDlFyPjqh9KLz5tR948KsM6b0X2RYgVT7rSRjQi68TOQHPX818M9+nStOJCGpA+UNEDsMkobd+lV8Yn/gSlKv0t8wkWdtRJZHFuygTRazHPZSGWry7BDM0c= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from SA0PR01MB6171.prod.exchangelabs.com (2603:10b6:806:e5::16) by SJ2PR01MB8372.prod.exchangelabs.com (2603:10b6:a03:542::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.15; Tue, 29 Oct 2024 16:54:24 +0000 Received: from SA0PR01MB6171.prod.exchangelabs.com ([fe80::b0e5:c494:81a3:5e1d]) by SA0PR01MB6171.prod.exchangelabs.com ([fe80::b0e5:c494:81a3:5e1d%6]) with mapi id 15.20.8114.015; Tue, 29 Oct 2024 16:54:24 +0000 From: admiyo@os.amperecomputing.com To: Sudeep Holla , Jassi Brar , Robert Moore , "Rafael J. Wysocki" , 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 v6 1/2] mctp pcc: Check before sending MCTP PCC response ACK Date: Tue, 29 Oct 2024 12:54:13 -0400 Message-Id: <20241029165414.58746-2-admiyo@os.amperecomputing.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241029165414.58746-1-admiyo@os.amperecomputing.com> References: <20241029165414.58746-1-admiyo@os.amperecomputing.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1PR13CA0168.namprd13.prod.outlook.com (2603:10b6:208:2bd::23) To SA0PR01MB6171.prod.exchangelabs.com (2603:10b6:806:e5::16) 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: SA0PR01MB6171:EE_|SJ2PR01MB8372:EE_ X-MS-Office365-Filtering-Correlation-Id: 84cb0494-66d2-48aa-f3a1-08dcf83a57b1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|7416014|366016|1800799024|10070799003; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?FvF36TRuD111b1BPkN6kpUvwhuL54LiIyUZ5rc2Y7I4AQG3LK5zUFhMbTGUm?= =?us-ascii?Q?5aRSXtd+Qc2W8LNBEJEmfCTKB6uJrrbsC1b1EiLvUGlSqRyZfw8bf/71PN4A?= =?us-ascii?Q?9d9VWlk1hLKEGg8o+TNA88YdbqJfxYWiCbsCsWS6Hjvc4FEaBvz0NNk6pZUs?= =?us-ascii?Q?7xQy0JKiY00ao1DRQ9nrw1g1ghRmfi9ip5BLCJIX9bziOVkl7vaGII/VWxD5?= =?us-ascii?Q?ok6EeIgFzVwNMkgbtIZGBWWi5Z+glmYKyNu1YCztII0lJvBreT6ZObGQAbuE?= =?us-ascii?Q?uwNm6NapE1vKWca8OZl2o/HNOKAeUHCLyphQBf8R2jGDuMeR/idhPYmo4qow?= =?us-ascii?Q?jjueWPvMDH7gyNs9xiSTj0+WZo+135R3KwyZATuD1ZxsJ3DoslgVdowr4yNT?= =?us-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T53uTBbV74ZABZbFGc?= =?us-ascii?Q?5PRsqWQUXv8WQQy/ohhhLHkt?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA0PR01MB6171.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(376014)(7416014)(366016)(1800799024)(10070799003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?aBxvJ4pAM6B9aCHnMrXLKUV0zhDVn86p8zUzmpVpLK9Hwy+vQkgzt1YWrJOh?= =?us-ascii?Q?xBI1fhRrSzJ23ykYz0b6A+OPni0RKRGl6L8s8EzMUUqWJcHgMS+9ONrMWUQJ?= =?us-ascii?Q?lAcpw6gfOE5a5NwU356a7/m8obGh0JTrShravlkZapxT6C/oZeVWL24+ShM5?= =?us-ascii?Q?ceV9dnTo8V5OhnBaetn27CmeDkzehPb2qxz6KIcfnP7We+rxe7iXf8cNZFel?= =?us-ascii?Q?/JxmPKXfMPBF8pJJiZy/LT+SFqtBq/l0AS4elDnmWIAGHFGElVjhyghDpUsa?= =?us-ascii?Q?awV4ZyftwxiK2ssh61XXbeRzy6jXXDec3gJWNUBZQ6lTgJgE/5h6GGYtp14Z?= =?us-ascii?Q?3FjiZD/es7B4LQhfZSSf3fKFqebPuoFfgz1GhSbIGWs3welJRLmDGC9ZDONe?= =?us-ascii?Q?Kgar9EuM3XHIU6FdCbAaJyAnugZQKNHzO5ZIBJURYREP4gQgr7dh2aqK6WGe?= =?us-ascii?Q?nNt9u8eHsj5nPyVlBxeNxs1Rc0QrbrNOyNVM2nT/h117IgdssNA3f+nuQdi4?= =?us-ascii?Q?ukD1bFm20yvYKzMctsmRHHSj+haXPjzyrUKFeXdiXgrU8F82uBGSQdJwfWnJ?= =?us-ascii?Q?hdVFYb4++kwODkwP8Zzt0n2MMFvWcQdwNpQFfuPVRd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oVt+sGyr7PV9hH09XO/SmoyXMFIIPE3tabJt?= =?us-ascii?Q?4eNwqnaMOHkkSvcVlmAgRamq0b34+EhheWeuuItROLwv6HsAM7lnjJ6Ijr2P?= =?us-ascii?Q?3KJjM7wFCXEVgEdVly6p3WBozWAZ/SW1mR99L3kUH1arjxYkCZueQ1+OyTQE?= =?us-ascii?Q?t4tLlGi2Y8ABfjNmDo8YVj5cRvg=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 84cb0494-66d2-48aa-f3a1-08dcf83a57b1 X-MS-Exchange-CrossTenant-AuthSource: SA0PR01MB6171.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 16:54:24.3849 (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: 6Did4/RbyayDuajF507bjQtgVMri8ULMIEJBnEJHXrLUMaxwAoAHHbitEfi0C1To4Jl4VBwrS6fqIq1b1M+U3bmSDEOJIU3n1LGNznmIvSQXkqBaK7DbWf0Xq1pUTL/3 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR01MB8372 Content-Type: text/plain; charset="utf-8" From: Adam Young Type 4 PCC channels have an option to send back a response to the platform when they are done processing the request. The flag to indicate whether or not to respond is inside the message body, and thus is not available to the pcc mailbox. In order to read the flag, this patch maps the shared buffer to virtual memory. If the flag is not set, still set command completion bit after processing message. Signed-off-by: Adam Young --- drivers/mailbox/pcc.c | 35 +++++++++++++++++++++++++++-------- include/acpi/pcc.h | 8 ++++++++ 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c index 94885e411085..b2a66e8a6cd6 100644 --- a/drivers/mailbox/pcc.c +++ b/drivers/mailbox/pcc.c @@ -90,6 +90,7 @@ struct pcc_chan_reg { * @cmd_complete: PCC register bundle for the command complete check regis= ter * @cmd_update: PCC register bundle for the command complete update regist= er * @error: PCC register bundle for the error status register + * @shmem_base_addr: the virtual memory address of the shared buffer * @plat_irq: platform interrupt * @type: PCC subspace type * @plat_irq_flags: platform interrupt flags @@ -107,6 +108,7 @@ struct pcc_chan_info { struct pcc_chan_reg cmd_complete; struct pcc_chan_reg cmd_update; struct pcc_chan_reg error; + void __iomem *shmem_base_addr; int plat_irq; u8 type; unsigned int plat_irq_flags; @@ -269,6 +271,27 @@ static bool pcc_mbox_cmd_complete_check(struct pcc_cha= n_info *pchan) return !!val; } =20 +static void check_and_ack(struct pcc_chan_info *pchan, struct mbox_chan *c= han) +{ + struct pcc_extended_type_hdr pcc_hdr; + + if (pchan->type !=3D ACPI_PCCT_TYPE_EXT_PCC_SLAVE_SUBSPACE) + return; + memcpy_fromio(&pcc_hdr, pchan->shmem_base_addr, + sizeof(struct pcc_extended_type_hdr)); + /* + * The PCC slave subspace channel needs to set the command complete bit + * after processing message. If the PCC_ACK_FLAG is set, it should also + * ring the doorbell. + * + * The PCC master subspace channel clears chan_in_use to free channel. + */ + if (le32_to_cpup(&pcc_hdr.flags) & PCC_ACK_FLAG_MASK) + pcc_send_data(chan, NULL); + else + pcc_chan_reg_read_modify_write(&pchan->cmd_update); +} + /** * pcc_mbox_irq - PCC mailbox interrupt handler * @irq: interrupt number @@ -306,14 +329,7 @@ static irqreturn_t pcc_mbox_irq(int irq, void *p) =20 mbox_chan_received_data(chan, NULL); =20 - /* - * The PCC slave subspace channel needs to set the command complete bit - * and ring doorbell after processing message. - * - * The PCC master subspace channel clears chan_in_use to free channel. - */ - if (pchan->type =3D=3D ACPI_PCCT_TYPE_EXT_PCC_SLAVE_SUBSPACE) - pcc_send_data(chan, NULL); + check_and_ack(pchan, chan); pchan->chan_in_use =3D false; =20 return IRQ_HANDLED; @@ -352,6 +368,9 @@ pcc_mbox_request_channel(struct mbox_client *cl, int su= bspace_id) if (rc) return ERR_PTR(rc); =20 + pchan->shmem_base_addr =3D devm_ioremap(chan->mbox->dev, + pchan->chan.shmem_base_addr, + pchan->chan.shmem_size); return &pchan->chan; } EXPORT_SYMBOL_GPL(pcc_mbox_request_channel); diff --git a/include/acpi/pcc.h b/include/acpi/pcc.h index 9b373d172a77..0bcb86dc4de7 100644 --- a/include/acpi/pcc.h +++ b/include/acpi/pcc.h @@ -18,6 +18,13 @@ struct pcc_mbox_chan { u16 min_turnaround_time; }; =20 +struct pcc_extended_type_hdr { + __le32 signature; + __le32 flags; + __le32 length; + char command[4]; +}; + /* Generic Communications Channel Shared Memory Region */ #define PCC_SIGNATURE 0x50434300 /* Generic Communications Channel Command Field */ @@ -31,6 +38,7 @@ struct pcc_mbox_chan { #define PCC_CMD_COMPLETION_NOTIFY BIT(0) =20 #define MAX_PCC_SUBSPACES 256 +#define PCC_ACK_FLAG_MASK 0x1 =20 #ifdef CONFIG_PCC extern struct pcc_mbox_chan * --=20 2.34.1 From nobody Mon Nov 25 04:25:27 2024 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2126.outbound.protection.outlook.com [40.107.93.126]) (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 80BCF1D95BE; Tue, 29 Oct 2024 16:54:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.126 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730220874; cv=fail; b=F4SJNmstBtOdrDz06qmVFr1ulFQbjzmf0FyQ8jejQIu1ZwYGiM0WcsC/dNM8+vIcttnh8MBnME6lpb+iOMU55jtCWk3Os5OPcBCUP1GeB6sm7gxW0tMfcd92XfVaDqhssMamI9scXIQsjuFSVyP2Q79ypqQuIhCEjD4GC5FDHF8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730220874; c=relaxed/simple; bh=Y9N4/9qqyLRXS9U5b7XP16LPgpOSfH/+4XBYzFFf8j4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Dv7EOG0lp1STPMVLyupbhJsTmJXkvE7jo6zMRxm+mpNNUu5m/KvGdhki/gjKiLu3AY5rO6OGCo2+fBceuh829ZAzWE+M7DqF25UxVh7my19iaibszEuet1f1633r8UszOKQNvghMp4dufV4k9rl6rI8k2dP4T5119WrDmbpCyzI= 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=fRfSPC6j; arc=fail smtp.client-ip=40.107.93.126 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="fRfSPC6j" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lY9PPk5eMRqEAMkMuHAD+ufS3gW6ZJZGdnVZJPp2z8INc3gh80v8zho2ruf48M6HKI3VC5mjZpHKdSk7VhQoWXO1tluA3w0vKlsj32ueVEQTW2VR6Fcn9iXQhqUbkK/ctS4JIyumuK7tzjt9g+uW29uDJE8Tir+w0cH/VGE7o54h7ONCuojijrVY98gthwbq60X6KPhmp/NeG0k08I1csOCyD2OcAqZn7UcC+Z/026uQP4lvJvx/mWr0i/GhhdTfkzONufK1nXbdcynzY7Yn+vW+8tsNu3NnrO8hZsyRfpJxbMsDf5nXzJvG6ASdOGUNkKQqqey3A8wkjsVPhM8izw== 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=MwOIlIsou09us1IUQ8OyuwDCoh8swhSvx4i/Eu0bhrg=; b=GNjkRyvSJxGAm454krr1ZWWbz3VjL5O+FBllDrXsvlV+fNUtMVxWQzXcnFpvSqX5RSwo1bAE94BcRAYNzbGNePbp4v5Lo68lSqtlV9ORXDe7VxHoE5oRDZGGxMN0HE9UKFP/RHRCZsUEqEWEErkW6sYDYjGyHol5RLHBCxTLp1VGmGy2oao2JQ6trJPy9L+2AjcGQGr0G4lOriHIaxy+wSnuvqmNMcGvLbBCqoDhISqYSFuo0q9TYamXp+K3ZKSuFjT/OPpWNiAdesX6YlWgRwkCdGUDQN1JMC9y3JDmzuRcCbKe7ULpYaUy6LiEkVrQp1nBpUCnFCOex+BpA2J5Jw== 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=MwOIlIsou09us1IUQ8OyuwDCoh8swhSvx4i/Eu0bhrg=; b=fRfSPC6jiGabJh4en+7aVj8VVWyE4ziWVRtVz80gOvxgowZItjakexxJerE/+fDA3tGuSCG7UQD8CKL/paNBcdNh98maPVyIkCKb8GUQzytjaHAcNuObBjCpXDiYWs+c1c9ZTiEhU9avvz0ye8VFNoO9a+YqPgQS+mBtf1GZiPw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from SA0PR01MB6171.prod.exchangelabs.com (2603:10b6:806:e5::16) by SJ2PR01MB8372.prod.exchangelabs.com (2603:10b6:a03:542::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.15; Tue, 29 Oct 2024 16:54:27 +0000 Received: from SA0PR01MB6171.prod.exchangelabs.com ([fe80::b0e5:c494:81a3:5e1d]) by SA0PR01MB6171.prod.exchangelabs.com ([fe80::b0e5:c494:81a3:5e1d%6]) with mapi id 15.20.8114.015; Tue, 29 Oct 2024 16:54:27 +0000 From: admiyo@os.amperecomputing.com To: Jeremy Kerr , Matt Johnston , "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 v6 2/2] mctp pcc: Implement MCTP over PCC Transport Date: Tue, 29 Oct 2024 12:54:14 -0400 Message-Id: <20241029165414.58746-3-admiyo@os.amperecomputing.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241029165414.58746-1-admiyo@os.amperecomputing.com> References: <20241029165414.58746-1-admiyo@os.amperecomputing.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL6PEPF00013E01.NAMP222.PROD.OUTLOOK.COM (2603:10b6:22e:400:0:1001:0:1c) To SA0PR01MB6171.prod.exchangelabs.com (2603:10b6:806:e5::16) 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: SA0PR01MB6171:EE_|SJ2PR01MB8372:EE_ X-MS-Office365-Filtering-Correlation-Id: 643aceac-7f17-46ce-544d-08dcf83a598c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|7416014|366016|1800799024|10070799003; X-Microsoft-Antispam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qws4xCO6EoH+iAuuW5kNMLOdfGIWvEoS7bpZ6bPzYmv?= =?us-ascii?Q?QQw/qOpLstFUQnZ9eSO8yeQ289oAmBsI8vAlTGseUAnrANDWXLQc9GlhvgIH?= =?us-ascii?Q?YSm88/C1yWIMsUCUMBvk2+Ck5Y1/51rjRYgW5unO0sGsOJemcnHMslOWePHf?= =?us-ascii?Q?oFzbk9NfE2C9LqLyqhWGjIwrADYgPwDZEQF4oc488oTKnulenrgYgKRuKUdj?= =?us-ascii?Q?lzEPo44VfrbzRjiFrRpMvI2/luGMD5UbXivU3zU7eB83ggf2RhJD76BJiuHg?= =?us-ascii?Q?Pmp7TinHS72mliODcUWGFRkL8yhcFIMoeAxDETj4q38JP/dD1nfgV9bfFrm7?= =?us-ascii?Q?kAyQxILObZVvD6U2mn3a+M3zPDAXL4lKNQsCDqHYU8ZsWym8BA+WEFOXuWfu?= =?us-ascii?Q?mKF7Zf3rTIP4Cq8UaWTN?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA0PR01MB6171.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(376014)(7416014)(366016)(1800799024)(10070799003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?kF0oYPx+2UAPcy3EfESUvmE+pCaSU/S5Ea9uRk97FCoCUzHJfH4PY/Mbj2QH?= =?us-ascii?Q?4gKY6zEDZUFNWX0qTb+rG7dealIUmENBMSXMJWVQHjtPq+hREFKLWZQjrUNP?= =?us-ascii?Q?xyV5cO1fIz7ySFSbk+AdUWBGp8saDEAec4bFcIT0fhBp0j3KITQPijJ4nXba?= =?us-ascii?Q?LterQhSrF8XbTCi+QHg2bvZ3yn0ByUqPnOf2pv084qkdW9/WoFyohxJQNo50?= =?us-ascii?Q?dB2ormbC5nXsc30r1VOcpPfxaKv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ii?Q?GqFrgqbqTMfRxWCxfpxEXMyMxBW0Tcj7hl0M8IoBeeufBsTNOlsgcsOiWPIm?= =?us-ascii?Q?/YFmxZr0EiDr3ooBf7CeqC5316tLGb2Q44bzH86t6jbwa27/l6is5p/dn7oC?= =?us-ascii?Q?1m+3iahgswqpOwrMQ4WgdrtXkXczS5yLiTOkl1DziGe3wNvPQUaK8+viA4+3?= =?us-ascii?Q?UUA/ttFE4HVCa/ldhXjcLRpbXzyotY3UtYzGz2HwQB+LqYX+eV70QhS3fzjp?= =?us-ascii?Q?/eEQWUJQ2oKoFJW/k/B59mqO5ksFww6Ns+RoKY3XT/Bw1eS2aU+937fuLKcG?= =?us-ascii?Q?ojCYt6MUlheJD5IIjSCVgzpdWpzDYizP3p0jDe7S70bM+KjdAlToEjADXRHg?= =?us-ascii?Q?wbXSYun79AcApqe+rMVeJhURGaf0ALzaLrOVyMFUJyUKrEWMjtLlYKr/CVIu?= =?us-ascii?Q?vTU8CcEk8Q1aaM9vjrbn4zsKIkZ8xb1+WBETeBpZJRpDbSVWfdjCeGvGGDgS?= =?us-ascii?Q?wcqJs7s1B9np81UsEgUK5GLZM1VPez+ytBK7VNj0dhb83iEUHRw2YtL0M0kJ?= =?us-ascii?Q?nMrky53/FPPidFyFCMPX1wQLLDc=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 643aceac-7f17-46ce-544d-08dcf83a598c X-MS-Exchange-CrossTenant-AuthSource: SA0PR01MB6171.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 16:54:27.5421 (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: 0gOgjrxgp4wHg8iakET0Web9vcXggQi6a01arJBFr5l6Mp58nnM7YkqdwORirIi4q2J3wBD9DJYhxUaCpQGovIvR/yr1INE5vpE7p1bEEuKzNdO3p64mAC1hV02l5Buf X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR01MB8372 Content-Type: text/plain; charset="utf-8" From: Adam Young Implementation of network driver for Management Control Transport Protocol(MCTP) over Platform Communication Channel(PCC) DMTF DSP:0292 https://www.dmtf.org/sites/default/files/standards/documents/DSP0292_1.0.0W= IP50.pdf MCTP devices are specified by entries in DSDT/SDST and reference channels specified in the PCCT. Communication with other devices use the PCC based doorbell mechanism. Signed-off-by: Adam Young --- drivers/net/mctp/Kconfig | 13 ++ drivers/net/mctp/Makefile | 1 + drivers/net/mctp/mctp-pcc.c | 332 ++++++++++++++++++++++++++++++++++++ 3 files changed, 346 insertions(+) create mode 100644 drivers/net/mctp/mctp-pcc.c diff --git a/drivers/net/mctp/Kconfig b/drivers/net/mctp/Kconfig index 15860d6ac39f..7e55db0fb7a0 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" + select 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 DST/SDST that matches the identifier. The Platform + commuinucation 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 e1cb99ced54a..492a9e47638f 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..b21fdca69538 --- /dev/null +++ b/drivers/net/mctp/mctp-pcc.c @@ -0,0 +1,332 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * mctp-pcc.c - Driver for MCTP over PCC. + * Copyright (c) 2024, Ampere Computing LLC + */ + +/* Implelmentation of MCTP over PCC DMTF Specification 256 + * https://www.dmtf.org/sites/default/files/standards/documents/DSP0256_2.= 0.0WIP50.pdf + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define MCTP_PAYLOAD_LENGTH 256 +#define MCTP_CMD_LENGTH 4 +#define MCTP_PCC_VERSION 0x1 /* DSP0253 defines a single version: 1= */ +#define MCTP_SIGNATURE "MCTP" +#define MCTP_SIGNATURE_LENGTH (sizeof(MCTP_SIGNATURE) - 1) +#define MCTP_HEADER_LENGTH 12 +#define MCTP_MIN_MTU 68 +#define PCC_MAGIC 0x50434300 +#define PCC_HEADER_FLAG_REQ_INT 0x1 +#define PCC_HEADER_FLAGS PCC_HEADER_FLAG_REQ_INT +#define PCC_DWORD_TYPE 0x0c + +struct mctp_pcc_hdr { + u32 signature; + u32 flags; + u32 length; + char mctp_signature[MCTP_SIGNATURE_LENGTH]; +}; + +struct mctp_pcc_mailbox { + u32 index; + struct pcc_mbox_chan *chan; + struct mbox_client client; + void __iomem *addr; +}; + +struct mctp_pcc_hw_addr { + __be32 parent_id; + __be16 inbox_id; + __be16 outbox_id; +}; + +/* The netdev structure. One of these per PCC adapter. */ +struct mctp_pcc_ndev { + /* spinlock to serialize access to PCC outbox buffer and registers + * Note that what PCC calls registers are memory locations, not CPU + * Registers. They include the fields used to synchronize access + * between the OS and remote endpoints. + * + * Only the Outbox needs a spinlock, to prevent multiple + * sent packets triggering multiple attempts to over write + * the outbox. The Inbox buffer is controlled by the remote + * service and a spinlock would have no effect. + */ + spinlock_t lock; + struct mctp_dev mdev; + 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 *c, void *buffe= r) +{ + struct mctp_pcc_ndev *mctp_pcc_dev; + struct mctp_pcc_hdr mctp_pcc_hdr; + struct mctp_skb_cb *cb; + struct sk_buff *skb; + void *skb_buf; + u32 data_len; + + mctp_pcc_dev =3D container_of(c, struct mctp_pcc_ndev, inbox.client); + memcpy_fromio(&mctp_pcc_hdr, mctp_pcc_dev->inbox.addr, + sizeof(struct mctp_pcc_hdr)); + data_len =3D mctp_pcc_hdr.length + MCTP_HEADER_LENGTH; + + if (data_len > mctp_pcc_dev->mdev.dev->mtu) { + mctp_pcc_dev->mdev.dev->stats.rx_dropped++; + return; + } + + skb =3D netdev_alloc_skb(mctp_pcc_dev->mdev.dev, data_len); + if (!skb) { + mctp_pcc_dev->mdev.dev->stats.rx_dropped++; + return; + } + mctp_pcc_dev->mdev.dev->stats.rx_packets++; + mctp_pcc_dev->mdev.dev->stats.rx_bytes +=3D data_len; + skb->protocol =3D htons(ETH_P_MCTP); + skb_buf =3D skb_put(skb, data_len); + memcpy_fromio(skb_buf, mctp_pcc_dev->inbox.addr, data_len); + + skb_reset_mac_header(skb); + skb_pull(skb, sizeof(struct mctp_pcc_hdr)); + 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 mctp_pcc_hdr mctp_pcc_header; + void __iomem *buffer; + unsigned long flags; + + ndev->stats.tx_bytes +=3D skb->len; + ndev->stats.tx_packets++; + + spin_lock_irqsave(&mpnd->lock, flags); + buffer =3D mpnd->outbox.addr; + mctp_pcc_header.signature =3D PCC_MAGIC | mpnd->outbox.index; + mctp_pcc_header.flags =3D PCC_HEADER_FLAGS; + memcpy(mctp_pcc_header.mctp_signature, MCTP_SIGNATURE, + MCTP_SIGNATURE_LENGTH); + mctp_pcc_header.length =3D skb->len + MCTP_SIGNATURE_LENGTH; + memcpy_toio(buffer, &mctp_pcc_header, sizeof(struct mctp_pcc_hdr)); + memcpy_toio(buffer + sizeof(struct mctp_pcc_hdr), skb->data, skb->len); + mpnd->outbox.chan->mchan->mbox->ops->send_data(mpnd->outbox.chan->mchan, + NULL); + spin_unlock_irqrestore(&mpnd->lock, flags); + + dev_consume_skb_any(skb); + return NETDEV_TX_OK; +} + +static void +mctp_pcc_net_stats(struct net_device *net_dev, + struct rtnl_link_stats64 *stats) +{ + stats->rx_errors =3D 0; + stats->rx_packets =3D net_dev->stats.rx_packets; + stats->tx_packets =3D net_dev->stats.tx_packets; + stats->rx_dropped =3D 0; + stats->tx_bytes =3D net_dev->stats.tx_bytes; + stats->rx_bytes =3D net_dev->stats.rx_bytes; +} + +static const struct net_device_ops mctp_pcc_netdev_ops =3D { + .ndo_start_xmit =3D mctp_pcc_tx, + .ndo_get_stats64 =3D mctp_pcc_net_stats, +}; + +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; +} + +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; + + switch (ares->type) { + case PCC_DWORD_TYPE: + break; + default: + 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 void mctp_cleanup_channel(void *data) +{ + struct pcc_mbox_chan *chan =3D data; + + pcc_mbox_free_channel(chan); +} + +static int mctp_pcc_initialize_mailbox(struct device *dev, + struct mctp_pcc_mailbox *box, u32 index) +{ + pr_info("index =3D %u", index); + box->index =3D index; + box->chan =3D pcc_mbox_request_channel(&box->client, index); + if (IS_ERR(box->chan)) + return PTR_ERR(box->chan); + box->addr =3D devm_ioremap(dev, box->chan->shmem_base_addr, + box->chan->shmem_size); + if (!box->addr) + return -EINVAL; + return devm_add_action_or_reset(dev, mctp_cleanup_channel, box->chan); +} + +static int mctp_pcc_driver_add(struct acpi_device *acpi_dev) +{ + struct mctp_pcc_lookup_context context =3D {0, 0, 0}; + struct mctp_pcc_hw_addr mctp_pcc_hw_addr; + 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; + int mctp_pcc_mtu; + 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, "FAILURE to lookup PCC indexes from CRS"); + return -EINVAL; + } + + //inbox initialization + snprintf(name, sizeof(name), "mctpipcc%d", context.inbox_index); + ndev =3D alloc_netdev(sizeof(struct mctp_pcc_ndev), name, NET_NAME_ENUM, + mctp_pcc_setup); + if (!ndev) + return -ENOMEM; + + mctp_pcc_ndev =3D netdev_priv(ndev); + rc =3D devm_add_action_or_reset(dev, mctp_cleanup_netdev, ndev); + if (rc) + goto cleanup_netdev; + spin_lock_init(&mctp_pcc_ndev->lock); + + rc =3D mctp_pcc_initialize_mailbox(dev, &mctp_pcc_ndev->inbox, + context.inbox_index); + if (rc) + goto cleanup_netdev; + mctp_pcc_ndev->inbox.client.rx_callback =3D mctp_pcc_client_rx_callback; + + //outbox initialization + rc =3D mctp_pcc_initialize_mailbox(dev, &mctp_pcc_ndev->outbox, + context.outbox_index); + if (rc) + goto cleanup_netdev; + + mctp_pcc_hw_addr.parent_id =3D cpu_to_be32(0); + mctp_pcc_hw_addr.inbox_id =3D cpu_to_be16(context.inbox_index); + mctp_pcc_hw_addr.outbox_id =3D cpu_to_be16(context.outbox_index); + ndev->addr_len =3D sizeof(mctp_pcc_hw_addr); + dev_addr_set(ndev, (const u8 *)&mctp_pcc_hw_addr); + + mctp_pcc_ndev->acpi_device =3D acpi_dev; + mctp_pcc_ndev->inbox.client.dev =3D dev; + mctp_pcc_ndev->outbox.client.dev =3D dev; + mctp_pcc_ndev->mdev.dev =3D ndev; + acpi_dev->driver_data =3D mctp_pcc_ndev; + + /* There is no clean way to pass the MTU to the callback function + * used for registration, so set the values ahead of time. + */ + mctp_pcc_mtu =3D mctp_pcc_ndev->outbox.chan->shmem_size - + sizeof(struct mctp_pcc_hdr); + ndev->mtu =3D MCTP_MIN_MTU; + ndev->max_mtu =3D mctp_pcc_mtu; + ndev->min_mtu =3D MCTP_MIN_MTU; + + /* ndev needs to be freed before the iomemory (mapped above) gets + * unmapped, devm resources get freed in reverse to the order they + * are added. + */ + rc =3D register_netdev(ndev); + return rc; +cleanup_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.34.1