From nobody Thu Nov 21 14:31:41 2024 Received: from SJ2PR03CU001.outbound.protection.outlook.com (mail-westusazon11022128.outbound.protection.outlook.com [52.101.43.128]) (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 D6DFE157A46; Wed, 20 Nov 2024 19:02:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.43.128 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732129352; cv=fail; b=iXlzllfs5gVtIzW9BzsGAjVIz355322TcLYd3HvavaPknHgSicbsMonahGUTby9VOlV88CzNqk/dChOUTpxn+hphX8zORhvziaA51xEHLzVRV5IE5Di/lUFZgf9uDSPe6aFFZ92vPGQC9/mls/esqvvHj/C06GDUuCNt5q/7Szg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732129352; c=relaxed/simple; bh=MToBTIDXZVv9GC1nLUmsGgTwVqmzbQC7qXXPEROJS2s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=L0RFfgGBrYHrtuFoeMojvwHWedIOMbEtfT3aeT8LoovRkM5/IMWLWazEkTfGTPwmu0wfvNE892/TOPZu2NXSKqCfOzAIk+JKsSkWTGpxVOstPOnQ8AmWaRrZK70lX1yy3PfeXtqJNTlq9kGqzsN2sBmwKE5iBKE+l3VO01FwNeg= 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=bVdPML6i; arc=fail smtp.client-ip=52.101.43.128 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="bVdPML6i" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OGf/i4Rn3F5qSO26tnzg0Z98FX7ICv+GjA+0vW4G/PGoRGfvSlw/ubz941is4kNZmkPMrSm04EG3wN/T4pVMT01wKNMWQwYwAdOAiVCQhcNlI3ZmH+nnGJ0BLV9++CuHqpM+50Xop9lgks1jNG4mZy1j/MGE7Yrnqp6wOQ5bzejugM3eZ/nsedi0y1q8kUY1bvE6eUmekUXMKzJ/Nm8/bZphadhZQgn8fNb1w2G7X1Yz6Tkp3DlObn57DPMrlKqzAzaDwxvJPMCf7uPI1afGYg+nd2qIckhoXfNJ/EgK7FqHP0DvhE31iLEpy5N0icI5OIVKmkqwPA6R8HzgBrWzQw== 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=2Hza19w1HWb2/O7bzh+mj9yUePdpxNjXqkMQ4ajTD9U=; b=r1ybgzsR0T4E2JfRTk1nEtDWjmJMo2AtL40c6j53h+jTJG2TTfNqkFbIJ+710rHnGLKGOtMJy9JPBeeQPA1HP5zJ30I2DDPqXWMWiWpFQmoNcdiCT7YxLhyy9J01FMvbKwDgL0x6HMIZPmHYr0aOCFYkIglfnwgDjmok/CtWCK85VKlLYbImUOkr+LO3R7Jl9ilERkMq2VGq+j1M+RZ4vXAIdgoxm2Tw5xufdXMDXx62fbwMWGCHsGElvEFxdkhRIly9ylwy4ULgK8asg6lKulw8ZKM83SuT+ftmTgu9dQxx1SZdi7qHTm3ys/7ybqZ+qOcSMqgOxePNmtPGXPfizA== 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=2Hza19w1HWb2/O7bzh+mj9yUePdpxNjXqkMQ4ajTD9U=; b=bVdPML6iBuBLkEBB35S0F6amEZiRNqayTN5OgWdoeuFmVBqyhZFRMaT03gQ0cEb2eruanGLXJ3Y1pg0AVZXscw7de8lCiveFCsgrRY0OONa+ZQo8rMwMPT9uy0OvbetYpGMPbFV5L50EAl37RCeE/htx239lM2a+5SdodxiGV7o= 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 BY3PR01MB6788.prod.exchangelabs.com (2603:10b6:a03:360::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.14; Wed, 20 Nov 2024 19:02:25 +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.8182.013; Wed, 20 Nov 2024 19:02:23 +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 v8 1/2] pcc: Check before sending MCTP PCC response ACK Date: Wed, 20 Nov 2024 14:02:14 -0500 Message-ID: <20241120190216.425715-2-admiyo@os.amperecomputing.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241120190216.425715-1-admiyo@os.amperecomputing.com> References: <20241120190216.425715-1-admiyo@os.amperecomputing.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: IA1P220CA0021.NAMP220.PROD.OUTLOOK.COM (2603:10b6:208:464::14) 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_|BY3PR01MB6788:EE_ X-MS-Office365-Filtering-Correlation-Id: 21c92248-183b-403e-de24-08dd0995dde3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|52116014|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?opxPU0KXnFcK2qrm8hDajwHB6nEFsDJoMI4cdDzPwQubS2wJuNRgmBKK6B4i?= =?us-ascii?Q?bN3tBWYzUH1zvAnmA2UaTqPhHxdf//RkTqdrks0Ucda/5D45aIOkuHmZrzBq?= =?us-ascii?Q?NFdD51ZA2QaRauq922qi11WdtHJsV+9vHNM0P42a8em2iyx14QGiN+8VAmbQ?= =?us-ascii?Q?sqOSht5pb5IYF9fsV4CVwytynrIGKEH2PqEYg2PwoXIWJdRzKZoGNePzjjkM?= =?us-ascii?Q?h0jmVwKpMVfviClzvnEQdr5M9522pE1cu3XkSHSml13gCNPZmMdY6Fsi20n7?= =?us-ascii?Q?TfQ1EBd9x3XhcPz5wzDhDyLFn8wlym0H94ugyBROirCRWyFEOuozLQfkgwI7?= =?us-ascii?Q?ISBmeebDd54DgBwwShoUtarS2+EoWJxMNmMv0faBLvQoAT199OBtRIg4KBff?= =?us-ascii?Q?ZuFcehVyTKVOvfI4t6gAE9mX3YGX9FysfGg7v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i7QqexjZBYLCuKTsGlD/?= 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)(10070799003)(52116014)(376014)(7416014)(366016)(1800799024);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?RxzQ9xBDvP6sX1CJaygtcNJ7K/WtEq8KCMivn2Hw7EnFkBXQuRhzkQ1SyBB6?= =?us-ascii?Q?drwqW2Bi/AGg9FlaDn+6W587/We3oiM/xlELP/5Xik/OWivZlQ7r0/podWyR?= =?us-ascii?Q?qRetaKz4RzOR8jf1INAqUu8uzxwcUNzWZqvUIdTVTvoY2g6yuBa2bcXIKgQn?= =?us-ascii?Q?L9JRk0G7ySDFCKMMtbqplj++t0F1bbH5N9oAl7pzPKm25jFU8fMKPXh78Ndj?= =?us-ascii?Q?Z+9ftYF3DnxnWPXolZUPjWIQyZEQMcOl9fas82mbnfvHXx3KASj6BpNZhIX7?= =?us-ascii?Q?OyV/3X3ERN2KHik6MAINeaLwsbTXsQLZUtfSIpqgZxZwUFy8CqkAQlGHHE8B?= =?us-ascii?Q?YMOmN6lL2OkBj1fdkOsYeDDVdNlT++HxJKp6KKy5nC4hUJTnzzzl1fzEtr4B?= =?us-ascii?Q?ibjzDFy/cbS8ytDmhH/Wljg6BCevlX+6A8D5rtPOQSj933jAcmUtYnswRIx0?= =?us-ascii?Q?8Lus0sYrB5az9hbbX4Rsnd8c9bMPVG0Z6jLNNr6CRnR7FOmrNTfnQooSf814?= =?us-ascii?Q?JhX7vlQf9wXIVA/G8ilMfCi2ymIaFLTkX2DawoWSIfbG73K6z4Kq1OPx3IwO?= =?us-ascii?Q?BhBe2atN9nAWgbQYLAqak9GSnzUJg1/TMXy7dvuvNH8J/jXBFRKH6rSFs91L?= =?us-ascii?Q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Xc49+J9C4OLOEqx1xgMiCBn?= =?us-ascii?Q?NJjuXUeM19TkhyB1o2ihR2byMavzGPE5M+31ZEloZjqurut8UL3LeA5hhr6c?= =?us-ascii?Q?Ek2GDk4izSD+unaO4zNN1xaFNzhLVCNQRqZRfTz6uS8BU4R7weJKjMM8jfEF?= =?us-ascii?Q?X4mJsEs093f+Mrc6mAYEGFf9qhY=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21c92248-183b-403e-de24-08dd0995dde3 X-MS-Exchange-CrossTenant-AuthSource: SA0PR01MB6171.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2024 19:02:23.5611 (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: kM/CBMa4hi6PR4IOm3cyDFwUtpnVeV9EzxT3XSyQxsDKqeQD03TcOckV7hfEWmTnv+sIe0F8sN++hQmmC9g8NJA45+JQDk1Fzj4kD6DpgkA1O0JNzPSJBVKJ6WlHG5l+ X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY3PR01MB6788 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. If the flag is not set, still set command completion bit after processing message. In order to read the flag, this patch maps the shared buffer to virtual memory. To avoid duplication of mapping the shared buffer is then made available to be used by the driver that uses the mailbox. Signed-off-by: Adam Young --- drivers/mailbox/pcc.c | 61 +++++++++++++++++++++++++++++++++++++------ include/acpi/pcc.h | 7 +++++ 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c index 94885e411085..82102a4c5d68 100644 --- a/drivers/mailbox/pcc.c +++ b/drivers/mailbox/pcc.c @@ -269,6 +269,35 @@ 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 acpi_pcct_ext_pcc_shared_memory pcc_hdr; + + if (pchan->type !=3D ACPI_PCCT_TYPE_EXT_PCC_SLAVE_SUBSPACE) + return; + /* If the memory region has not been mapped, we cannot + * determine if we need to send the message, but we still + * need to set the cmd_update flag before returning. + */ + if (pchan->chan.shmem =3D=3D NULL) { + pcc_chan_reg_read_modify_write(&pchan->cmd_update); + return; + } + memcpy_fromio(&pcc_hdr, pchan->chan.shmem, + sizeof(struct acpi_pcct_ext_pcc_shared_memory)); + /* + * 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 +335,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; @@ -365,14 +387,37 @@ EXPORT_SYMBOL_GPL(pcc_mbox_request_channel); void pcc_mbox_free_channel(struct pcc_mbox_chan *pchan) { struct mbox_chan *chan =3D pchan->mchan; + struct pcc_chan_info *pchan_info; + struct pcc_mbox_chan *pcc_mbox_chan; =20 if (!chan || !chan->cl) return; + pchan_info =3D chan->con_priv; + pcc_mbox_chan =3D &pchan_info->chan; + if (pcc_mbox_chan->shmem) { + iounmap(pcc_mbox_chan->shmem); + pcc_mbox_chan->shmem =3D NULL; + } =20 mbox_free_channel(chan); } EXPORT_SYMBOL_GPL(pcc_mbox_free_channel); =20 +int pcc_mbox_ioremap(struct mbox_chan *chan) +{ + struct pcc_chan_info *pchan_info; + struct pcc_mbox_chan *pcc_mbox_chan; + + if (!chan || !chan->cl) + return -1; + pchan_info =3D chan->con_priv; + pcc_mbox_chan =3D &pchan_info->chan; + pcc_mbox_chan->shmem =3D ioremap(pcc_mbox_chan->shmem_base_addr, + pcc_mbox_chan->shmem_size); + return 0; +} +EXPORT_SYMBOL_GPL(pcc_mbox_ioremap); + /** * 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 9b373d172a77..699c1a37b8e7 100644 --- a/include/acpi/pcc.h +++ b/include/acpi/pcc.h @@ -12,6 +12,7 @@ struct pcc_mbox_chan { struct mbox_chan *mchan; u64 shmem_base_addr; + void __iomem *shmem; u64 shmem_size; u32 latency; u32 max_access_rate; @@ -31,11 +32,13 @@ 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 * 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_ioremap(struct mbox_chan *chan); #else static inline struct pcc_mbox_chan * pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id) @@ -43,6 +46,10 @@ 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_ioremap(struct mbox_chan *chan) +{ + return 0; +}; #endif =20 #endif /* _PCC_H */ --=20 2.43.0 From nobody Thu Nov 21 14:31:41 2024 Received: from SJ2PR03CU001.outbound.protection.outlook.com (mail-westusazon11022128.outbound.protection.outlook.com [52.101.43.128]) (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 92FA11BA272; Wed, 20 Nov 2024 19:02:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.43.128 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732129354; cv=fail; b=TcUpKPwFhamhpiMEb/MEdoyItTIT41d4Kvhu4Ed76t85Bgm4rTVccS7HpNI1H2s/qz5X7qRB7iSk7xPP9MJ7YVA7OlWgQ1fN3JbwYb+h2QiBFbkv3n0MHUVDnmI1/Xy/tdm8Cyw/e632ZtKzTqMcKl4Yw+nmsUyAaJoH04uUpbU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732129354; c=relaxed/simple; bh=f++X1TiDtEUpo+i/KpvXl2WyDsiYMF3oNg5X9AVgCh8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=XWCQzKDeNzwgkRBP9j+f6iILFFSFsQTvsXybTlO0UClatEAChTKStsh6EVnN2SFX1GkjwueXWFDWBnc/EXB2PVXVLrJUaahz6nS3m4qLqsEG0Y6bze77CBsJ21n4h01svyFIwwUHcnjZiz5eHX/dXFDj0QE9SYlGvMcMbIewRh4= 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=O/07Z96v; arc=fail smtp.client-ip=52.101.43.128 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="O/07Z96v" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ysq6rL1N1eyaL8BTmd9QqMInClxobFqXYeoMI5Vujbt7e0iaEXlXw22Zb5SDp/NRRBo49qN0lryMp8IGLGje2hZszWr95cgrKq7zc/8zubP9MV+UhfXk4cKYiqMURdRyK0YUJ0vRwHCOHh9ruk7w+2a5u+oWZ3qH6x5rNRlCuGPh8C3OnJGVCG5WP1nv8RN67E4s8P8hfNfQR+WWZ5otWr2By0r58n+ym94uBUM+O3zKP6pBtn2q2jy946uKNGx2YomEPNMYhKVnx5LBSE6jQwNHjyb/xEQn2VRqYguN/AJjSyA9XvzqCao++v4qIUY4krnAQm8ijw6WshDzetvLag== 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=eoaP9WNTf5wmvZyu6GcoQqFZKcIhdp6P/7rx/8jG8Ew=; b=PJB0rn6H6xafIinuCZUXxYitj90RnT9YYse2vXeXDxyIx8y9nR67UwLxflLVfZW1LssIj7VWzOd2kgnp6enaE0VVxb25e2CzB3xdtSGB9vnbtRwun6QVkau3tak0VHN7v3VSv/IHchThLWKpPQyeToacTO1uiucSLS+DEasxOiqUAxCcTeC/lJhpYoaxGo/YXY9EV7YqZOjgFzdTnT36Nykl5jQU/lWN+GMQljyFnedVozlRwgP7oqa/kSO3Nr7gzfKtUjMsFbnRLrP94wqro8i+665KedhoUXLB87+daLVq79+trnivbQ8ofRtMJ6llZy+FCh9cLPwQiBEjdbrmCQ== 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=eoaP9WNTf5wmvZyu6GcoQqFZKcIhdp6P/7rx/8jG8Ew=; b=O/07Z96vCsNaxoiwfmtjKhNUPvOkTUFPycPyO331hwrYnjyF34rNIccW7HAANxKeaOm17Z5PERQt7hHDFeAuv0hViV5g25QakSDOxWtPQj84cdnJ/qjE5gE5OIx9p/drPnxBcXfbGjKVE/ajHGEthwydePNr9oF9X649WRNp+IE= 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 BY3PR01MB6788.prod.exchangelabs.com (2603:10b6:a03:360::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.14; Wed, 20 Nov 2024 19:02:25 +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.8182.013; Wed, 20 Nov 2024 19:02:25 +0000 From: admiyo@os.amperecomputing.com 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 v8 2/2] mctp pcc: Implement MCTP over PCC Transport Date: Wed, 20 Nov 2024 14:02:15 -0500 Message-ID: <20241120190216.425715-3-admiyo@os.amperecomputing.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241120190216.425715-1-admiyo@os.amperecomputing.com> References: <20241120190216.425715-1-admiyo@os.amperecomputing.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL0PR0102CA0022.prod.exchangelabs.com (2603:10b6:207:18::35) 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_|BY3PR01MB6788:EE_ X-MS-Office365-Filtering-Correlation-Id: 0dbcdcd2-dce7-478c-1658-08dd0995df19 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|52116014|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?cLyLfRNiU49izYO21bpPEohOGVaJn5LlNlV3+ZENCMbbmoL9ztOlSp14m8DE?= =?us-ascii?Q?jqLnHbMVqRCgJ4mnl3Zs24+Kq4y7AtsMMkmy1G6tDevbxv4K/oLmnV8gCgbV?= =?us-ascii?Q?PetQGCBIUmuD3yA6xEcVQib3G5rM9QpUX6bLOzDGezBRWvItwHXKkqru/DZ1?= =?us-ascii?Q?2ATndoHFlec9bG0yVpQgFJyFuOdC9cRfFTRA0b72p6wCInsqiThS9iOQT8rz?= =?us-ascii?Q?pOHiCkOWhYJfn/QoykOQNa2G4PNNimvZYA6vnNO9OV32uQ3NyWUOSI/aRX+M?= =?us-ascii?Q?TQ6Et+qqDb0wVYtXhAdaIaovnWCWtulmox4MBnZ67hpIekzFgGQ5hvomfMKW?= =?us-ascii?Q?Q6P9CR1BJIW7gISNIg/up/3lkOhH3hOwAm12HVE0SM6pzXdCw/LWqjr2TSW7?= =?us-ascii?Q?1Ctn74QYFkqB3HERLcZLud1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?= 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)(10070799003)(52116014)(376014)(7416014)(366016)(1800799024);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?tWgs2xKD+gQ8zOE6+8U2nfUl1g+fUujtVunN4wk4mpLH/1IAfuKwhUPctSxL?= =?us-ascii?Q?WdyFY2ViP99ZA8Y07Bc1nlxr/miII5ChyF3XpF+zJbBtQBQizU0mZ2GMHwSs?= =?us-ascii?Q?C14NzoGo2Z6wSTqx0wIRtULBNpdWBsaZWkH/Pvf7odPt+Ud8zJg1o8ulqCHP?= =?us-ascii?Q?f9wxrCm/gfdqdI/IY+wqUqXc8FhJyxFLFwwIqtAjeE0m0l8R3bWHk47QYC7V?= =?us-ascii?Q?nDji9GRiybhW1Z38IA3OmO5fBmk/Z8XByJFJBLvJHRyUA4opKqFeu/8j92GV?= =?us-ascii?Q?eaknFzV9JPup++AdQQEearBFdsgf6yCsnUeQjKU48lbuBxS9Fls/b2FUd746?= =?us-ascii?Q?/Orx95DXsuwOPgORp2hBfKkeG3LSZRNSMCYkKdIGE78FdAaEV2aAl3+jDO9u?= =?us-ascii?Q?gSLUV6wjbaHBPXJ4lSRQu0FFkp4gHBiJjkX3g5aDe0ggdYzrfNB70hmQ7Jbs?= =?us-ascii?Q?R6QlNJXY4qvAUGwWftk3lm3q+9M/YvD+v42OaTsLbco/unwBKEA2J/I6kaAU?= =?us-ascii?Q?XUH2rLyt6gLUm85FfckIkqWwz1kXQNPklkVN5trRSjlR7w5RQL4aKZLLQbgN?= =?us-ascii?Q?kH4LWMjy0RYlx+fLyJFOoivnuILwrLKYonVvUJ3Z53xxzzdIkXk5p/2XICAX?= =?us-ascii?Q?095B0jOXyWr2WJYL5CEEI0C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?eS8ZkBi5EhGZYit1s8ufb3BjU/cUThnIDNhcDzUcs/TvaAv/5Sp/1A3uPIRs?= =?us-ascii?Q?4CpcdUrOTP+C1DVkOx7+Kfv99igzmMY/pumXob58jvUMgNSi+EXUK8fkmdEy?= =?us-ascii?Q?L85lIkRP9VRWcGDZUnqas7VS0eo=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0dbcdcd2-dce7-478c-1658-08dd0995df19 X-MS-Exchange-CrossTenant-AuthSource: SA0PR01MB6171.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2024 19:02:25.5358 (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: VTFG0AJWBlfg5r5IWmjhCrmO1+oAgvwZu0K2s49Y6yZr1mxvLpqPtFyR90AI+gyYouxUd675D/gSN0fjC+toYQsRI/7Rv2YAViPi/5uIDdBxmCESfifvhU3m6o/p54Zq X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY3PR01MB6788 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 | 321 ++++++++++++++++++++++++++++++++++++ 3 files changed, 335 insertions(+) create mode 100644 drivers/net/mctp/mctp-pcc.c diff --git a/drivers/net/mctp/Kconfig b/drivers/net/mctp/Kconfig index 15860d6ac39f..073eb2a21841 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 DST/SDST 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 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..c1c28d3c24cc --- /dev/null +++ b/drivers/net/mctp/mctp-pcc.c @@ -0,0 +1,321 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * mctp-pcc.c - Driver for MCTP over PCC. + * Copyright (c) 2024, Ampere Computing LLC + */ + +/* Implementation of MCTP over PCC DMTF Specification DSP0256 + * 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 { + __be32 signature; + __be32 flags; + __be32 length; + char mctp_signature[MCTP_SIGNATURE_LENGTH]; +}; + +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 { + /* 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.chan->shmem, + 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.chan->shmem, 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; + int len =3D skb->len; + + ndev->stats.tx_bytes +=3D skb->len; + ndev->stats.tx_packets++; + + spin_lock_irqsave(&mpnd->lock, flags); + mctp_pcc_header =3D skb_push(skb, sizeof(struct mctp_pcc_hdr)); + buffer =3D mpnd->outbox.chan->shmem; + 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 len + MCTP_SIGNATURE_LENGTH; + + memcpy_toio(buffer, 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 net_dev->stats.rx_dropped; + 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) +{ + int ret; + + box->index =3D index; + box->chan =3D pcc_mbox_request_channel(&box->client, index); + if (IS_ERR(box->chan)) + return PTR_ERR(box->chan); + devm_add_action_or_reset(dev, mctp_cleanup_channel, box->chan); + ret =3D pcc_mbox_ioremap(box->chan->mchan); + if (ret) + return -EINVAL; + return 0; +} + +static int mctp_pcc_driver_add(struct acpi_device *acpi_dev) +{ + struct mctp_pcc_lookup_context context =3D {0, 0, 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; + 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\n"); + 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_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.43.0