From nobody Tue Oct 7 03:47:44 2025 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11023106.outbound.protection.outlook.com [40.107.201.106]) (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 70DE02E3710; Tue, 15 Jul 2025 00:10:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.201.106 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752538225; cv=fail; b=k9hGefv4jigsh5MXY5KMuQRHGlRjYrK3wM6cyj9RPFid1CzHa1Ivyu6DwwDmOr/Hp3ehSlQi8oqGjKY+ArZUFEchTHolwzqE4jLNFUBEN5kxYm5qmppbB2pRkYQk1Kteys8X3hbLwnny6dG7Od83lvCxpCG6UFdgswvvHhojdE8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752538225; c=relaxed/simple; bh=q9aGkqUdXoCuQcduWQCxXhWCjt0dKkYiOUy7pKN/Y1o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=D++EBe7KwxxPPL5GJEBHEyeC7UuH6PeRDpf4D7QRrUqfz2260oJb+bbnylKyNIcLpEVbNk/3WsWcmIjsfcURq/LwbBelkXYP20Rgx99u3lYW/FMO7Ej2iCxNyiPIfYd46mr6rjGNzV1HpAyCAeqsRBMr+Vm7dh2TI/RkDf1XOZc= 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=JLaTZvN8; arc=fail smtp.client-ip=40.107.201.106 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="JLaTZvN8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FLZNsoTYcOcKLbFdMIqysVdKOu+M6aehFnycBXQARUMbL+RsqUpk11GUFk3XunQIeiT/HPiGOrdd8DjWcmDS1AB8373VYXelUrK34nZkoeIFhpMKmGfcDHcrc+1VWzaTS55uhUOlDPwPfALFTpKEep3QVrXPDls6SBHVcdiW9mzieuRmppbD0+xfTNDX7WW5kgaalO9EGsx9STJvJOq2HGTuzqPgK/p5/BZCGxAuDF+4KvxbRhv+oH27ol8LrBrHBYzZmZVEWAkdy58lCT7beb+l0gHOt1uZWZ5xq3aD0P6dtHf877YC+STk5Z6nR3i8vnRxaau8T499fN8q+AbZ9g== 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=abIq3tdjexqmMwqYsCYOLvYaie3jVotMFTGPpDC51o8=; b=ST1HzpF3NZYUVOhsfZMbO4B/rad9yE8E9pTv87v1vAjaKMbhrhFpEUjJ8+AbH7hC0DqdzJWK9kOmVNRqF3ysSJwXfxF85+fbtQ1FjUTcp3DnGMaJIrMAXJcTCbsY4pB3jqdMaQLOFxS4zlPQZawmMKS63tzJxWxmDgQ8LwYwx6H3QWJw2TjA0+4M5zWyFBxzW2iZm7J+hQ0z93XenxDuNGLVlWjKbIQuu/YhaxkX3rvyLBJATYQRQZC1bk6bN9KzEWCmvKQvjfzvfPohj8DFFpmxdo+ILj/x1EZ14/b0O4rE62vwTfoeHwtOGzEdYOefzSEkWMkacJlKk/Ka3ZHI/w== 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=abIq3tdjexqmMwqYsCYOLvYaie3jVotMFTGPpDC51o8=; b=JLaTZvN8KZMoI0fdkUlbIVbQ4mwAQVNNu6VW6g5SsUz0tiatkWLJP5YTQcjE+bb6oqMM6qV729LgGFA1yokN+Ik1itCJByN5QiLb3TZrstWQ1sBn4iAjqLr1RV56/gEGsW3D42k8JTdlskoXF9Xbm3i4KmOOJpvXzWB0815wTgs= 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 SJ0PR01MB6239.prod.exchangelabs.com (2603:10b6:a03:29d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8922.32; Tue, 15 Jul 2025 00:10:20 +0000 Received: from BN3PR01MB9212.prod.exchangelabs.com ([fe80::3513:ad6e:208c:5dbd]) by BN3PR01MB9212.prod.exchangelabs.com ([fe80::3513:ad6e:208c:5dbd%4]) with mapi id 15.20.8922.028; Tue, 15 Jul 2025 00:10:20 +0000 From: admiyo@os.amperecomputing.com To: Sudeep Holla , Jassi Brar , "Rafael J. Wysocki" , Len Brown , Robert Moore Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jeremy Kerr , Matt Johnston , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Cameron , Huisong Li Subject: [PATCH v23 1/2] mailbox/pcc: support mailbox management of the shared buffer Date: Mon, 14 Jul 2025 20:10:07 -0400 Message-ID: <20250715001011.90534-2-admiyo@os.amperecomputing.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250715001011.90534-1-admiyo@os.amperecomputing.com> References: <20250715001011.90534-1-admiyo@os.amperecomputing.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SA1PR03CA0023.namprd03.prod.outlook.com (2603:10b6:806:2d3::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_|SJ0PR01MB6239:EE_ X-MS-Office365-Filtering-Correlation-Id: 29b0ce6b-1d0b-4bb7-a478-08ddc333fc4a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|52116014|366016|1800799024|10070799003; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Sd/9IvQVQGwMR2mokdXaYsd8AbTY1yUJaBGJ/APHk0s9v+ZI1wnEPpBTsQMd?= =?us-ascii?Q?KsnlRA2r2EWAUN8NjapsSsJAdSu5gbq5cBK9EvrG27HMzeTvt8ZQN5l1de0m?= =?us-ascii?Q?OfoW+3omnG1KNiQufq54PRzqsRhcU1hn7hQ/lfgZuzA6BQ8ayMQe1tfzR9I1?= =?us-ascii?Q?Bixmx4oJLMTW6aw28QVh9MEtPq+2ssMujLsCOjqUjp9BjxfkdGKoDPhoOCli?= =?us-ascii?Q?o1umxJ3CnsKtw58AYD285O9YXyhUHkJfXPWVFZDb7tRfpZedOVAc15RIvZsc?= =?us-ascii?Q?FKeXg7bAGAKw86dunS5IWZXesCB01OWPM24WU96LUyA/Yig7ZGqh84uWqNjW?= =?us-ascii?Q?n5r2AQc/z7jn/smKW0CldJ4cGIOK6TvKP4xSXQl/xrnHof8pi63oUAUOEwZX?= =?us-ascii?Q?VrB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Naw71kXL+oBQvsptporGyuISLo?= =?us-ascii?Q?NtVyTwl3ICn5yTwohsoPDMiRGEZCovWH0KCyNHNHwgiAX+ooyNo1T330ESa5?= =?us-ascii?Q?1I5TdrSfDtwrJq9TxpBlICT45b8x11UZeptaGmm3+sC5c/7TnCuiNHcXDUVS?= =?us-ascii?Q?hB2JFpcy1VQ=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN3PR01MB9212.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(52116014)(366016)(1800799024)(10070799003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?QHNam7g+8LyxZDsj8GXw+AUvGRNAMC9acdtjKc9gIXalEtKFQ2H4qr98uQ10?= =?us-ascii?Q?WiYzGtLLP44PNbRo1XaU1arwXidcKAhKIiNkreHMcMkOzAEnHg5+Wu2XhsCy?= =?us-ascii?Q?iXw3UFXGflmBJRS8N2sWqvectt+wQuzvhV2rmR28ZtvCfrnLVikxOx9rfsUS?= =?us-ascii?Q?V5L9ZTIPUG8gb9uAA7RTMjfZeBR3FU7B1WmeOjbGVB/hF+CGNtW+vZOe04Bf?= =?us-ascii?Q?si1cRgl//G82gC22Gwa1YzC5ilvIMrjtdv+lHr+Z+R7P+rMY6aYBMFdDLzXR?= =?us-ascii?Q?hrN0/Z8uKTQo+O/eRQl7m3b9F8AvLkrYWH25N8fT+sDX6GQba0RG68QsBxM+?= =?us-ascii?Q?H74gUU99x+CUKPoA3YpKZQU+Umuh3OHlLQv0pqKgqipTlVoXSFjR4DEe76Mu?= =?us-ascii?Q?JW58Sai0f8sEit15doqOjEgDur/8E7IUcheC4BfHH6awxvb+rK8VFD7uuten?= =?us-ascii?Q?Z58mjR/vCTdEkHbhNH/uv94d3XXnGBCLT/7DnfbOWB6IZUXkEI2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yKSGMPJwsLth2mVwEKj1D0GIYiXn3aq08MD?= =?us-ascii?Q?8wItgCFdJfOaOTAv6I7D9k/amPQOgiCdW9Z1r3Y8coMP3b1EDQgnD/eM2aih?= =?us-ascii?Q?/44uLZPkGNDc2rKzZv74hTCVFDbfXUdwDoJ/ueqPVEagpuJXEKBH+razEi+a?= =?us-ascii?Q?2RJ+yGxMaBq/gXaKa9ZZAq5sHERi5w9Nf9bnXI374hqb/qe3JpCiDLl9NfrS?= =?us-ascii?Q?57vfDim5tVJNXtSBj+VDEoV4VQ5b3tTxCVuK6RgtrW6Shgq71CkXTRh70KnW?= =?us-ascii?Q?CIw8oU+69oS8Ea1/OXFlvYarDVM=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 29b0ce6b-1d0b-4bb7-a478-08ddc333fc4a X-MS-Exchange-CrossTenant-AuthSource: BN3PR01MB9212.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 00:10:20.1717 (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: Ocm6RQKs7pIpA7BOXhtSDjnM3siWyr+kCC2kx3vySev8n6ko9ngU2PfsTMa2HTGnsMxTrv96W+9JdwX33MMk82lkRptX1SHk2bX5wdFs3YmgYL+iSrknqe5pa3o1h24C X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR01MB6239 Content-Type: text/plain; charset="utf-8" From: Adam Young Define a new, optional, callback that allows the driver to specify how the return data buffer is allocated. If that callback is set, mailbox/pcc.c is now responsible for reading from and writing to the PCC shared buffer. This also allows for proper checks of the Commnand complete flag between the PCC sender and receiver. For Type 4 channels, initialize the command complete flag prior to accepting messages. Since the mailbox does not know what memory allocation scheme to use for response messages, the client now has an optional callback that allows it to allocate the buffer for a response message. When an outbound message is written to the buffer, the mailbox checks for the flag indicating the client wants an tx complete notification via IRQ. Upon receipt of the interrupt It will pair it with the outgoing message. The expected use is to free the kernel memory buffer for the previous outgoing message. Signed-off-by: Adam Young --- drivers/mailbox/pcc.c | 102 ++++++++++++++++++++++++++++++++++++++++-- include/acpi/pcc.h | 29 ++++++++++++ 2 files changed, 127 insertions(+), 4 deletions(-) diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c index f6714c233f5a..0a00719b2482 100644 --- a/drivers/mailbox/pcc.c +++ b/drivers/mailbox/pcc.c @@ -306,6 +306,22 @@ static void pcc_chan_acknowledge(struct pcc_chan_info = *pchan) pcc_chan_reg_read_modify_write(&pchan->db); } =20 +static void *write_response(struct pcc_chan_info *pchan) +{ + struct pcc_header pcc_header; + void *buffer; + int data_len; + + memcpy_fromio(&pcc_header, pchan->chan.shmem, + sizeof(pcc_header)); + data_len =3D pcc_header.length - sizeof(u32) + sizeof(struct pcc_header); + + buffer =3D pchan->chan.rx_alloc(pchan->chan.mchan->cl, data_len); + if (buffer !=3D NULL) + memcpy_fromio(buffer, pchan->chan.shmem, data_len); + return buffer; +} + /** * pcc_mbox_irq - PCC mailbox interrupt handler * @irq: interrupt number @@ -317,6 +333,8 @@ static irqreturn_t pcc_mbox_irq(int irq, void *p) { struct pcc_chan_info *pchan; struct mbox_chan *chan =3D p; + struct pcc_header *pcc_header =3D chan->active_req; + void *handle =3D NULL; =20 pchan =3D chan->con_priv; =20 @@ -340,7 +358,17 @@ static irqreturn_t pcc_mbox_irq(int irq, void *p) * required to avoid any possible race in updatation of this flag. */ pchan->chan_in_use =3D false; - mbox_chan_received_data(chan, NULL); + + if (pchan->chan.rx_alloc) + handle =3D write_response(pchan); + + if (chan->active_req) { + pcc_header =3D chan->active_req; + if (pcc_header->flags & PCC_CMD_COMPLETION_NOTIFY) + mbox_chan_txdone(chan, 0); + } + + mbox_chan_received_data(chan, handle); =20 pcc_chan_acknowledge(pchan); =20 @@ -384,9 +412,24 @@ pcc_mbox_request_channel(struct mbox_client *cl, int s= ubspace_id) pcc_mchan =3D &pchan->chan; pcc_mchan->shmem =3D acpi_os_ioremap(pcc_mchan->shmem_base_addr, pcc_mchan->shmem_size); - if (pcc_mchan->shmem) - return pcc_mchan; + if (!pcc_mchan->shmem) + goto err; + + 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 + * the mailbox API. That implies that the mailbox client must + * have set the allocate callback function prior to + * sending any messages. + */ + if (pchan->type =3D=3D ACPI_PCCT_TYPE_EXT_PCC_SLAVE_SUBSPACE) + pcc_chan_reg_read_modify_write(&pchan->cmd_update); + + return pcc_mchan; =20 +err: mbox_free_channel(chan); return ERR_PTR(-ENXIO); } @@ -417,8 +460,38 @@ void pcc_mbox_free_channel(struct pcc_mbox_chan *pchan) } EXPORT_SYMBOL_GPL(pcc_mbox_free_channel); =20 +static int pcc_write_to_buffer(struct mbox_chan *chan, void *data) +{ + struct pcc_chan_info *pchan =3D chan->con_priv; + struct pcc_mbox_chan *pcc_mbox_chan =3D &pchan->chan; + struct pcc_header *pcc_header =3D data; + + if (!pchan->chan.manage_writes) + return 0; + + /* The PCC header length includes the command field + * but not the other values from the header. + */ + int len =3D pcc_header->length - sizeof(u32) + sizeof(struct pcc_header); + u64 val; + + pcc_chan_reg_read(&pchan->cmd_complete, &val); + if (!val) { + pr_info("%s pchan->cmd_complete not set", __func__); + return -1; + } + memcpy_toio(pcc_mbox_chan->shmem, data, len); + return 0; +} + + /** - * pcc_send_data - Called from Mailbox Controller code. Used + * pcc_send_data - Called from Mailbox Controller code. If + * pchan->chan.rx_alloc is set, then the command complete + * flag is checked and the data is written to the shared + * buffer io memory. + * + * If pchan->chan.rx_alloc is not set, then it is used * here only to ring the channel doorbell. The PCC client * specific read/write is done in the client driver in * order to maintain atomicity over PCC channel once @@ -434,17 +507,37 @@ static int pcc_send_data(struct mbox_chan *chan, void= *data) int ret; struct pcc_chan_info *pchan =3D chan->con_priv; =20 + ret =3D pcc_write_to_buffer(chan, data); + if (ret) + return ret; + ret =3D pcc_chan_reg_read_modify_write(&pchan->cmd_update); if (ret) return ret; =20 ret =3D pcc_chan_reg_read_modify_write(&pchan->db); + if (!ret && pchan->plat_irq > 0) pchan->chan_in_use =3D true; =20 return ret; } =20 + +static bool pcc_last_tx_done(struct mbox_chan *chan) +{ + struct pcc_chan_info *pchan =3D chan->con_priv; + u64 val; + + pcc_chan_reg_read(&pchan->cmd_complete, &val); + if (!val) + return false; + else + return true; +} + + + /** * pcc_startup - Called from Mailbox Controller code. Used here * to request the interrupt. @@ -490,6 +583,7 @@ static const struct mbox_chan_ops pcc_chan_ops =3D { .send_data =3D pcc_send_data, .startup =3D pcc_startup, .shutdown =3D pcc_shutdown, + .last_tx_done =3D pcc_last_tx_done, }; =20 /** diff --git a/include/acpi/pcc.h b/include/acpi/pcc.h index 840bfc95bae3..9af3b502f839 100644 --- a/include/acpi/pcc.h +++ b/include/acpi/pcc.h @@ -17,6 +17,35 @@ 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); +}; + +struct pcc_header { + u32 signature; + u32 flags; + u32 length; + u32 command; }; =20 /* Generic Communications Channel Shared Memory Region */ --=20 2.43.0 From nobody Tue Oct 7 03:47:44 2025 Received: from BN8PR05CU002.outbound.protection.outlook.com (mail-eastus2azon11021078.outbound.protection.outlook.com [52.101.57.78]) (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 9451F2BAF7; Tue, 15 Jul 2025 00:10:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.57.78 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752538229; cv=fail; b=WgoF2m/e/LemeESZ1XB3R/wbbk3Xw2K/0UWhksIjAK4Ihmy9G8aqk7rcHG38YDQ0Flo3cK6ANQpCZ4m0s7DL5Qrpt4yqekdIl9t8CPbKgzGJspc51Zq3alX8kn11nXDyAL8e0OhT/XMnoCa25+/AuP6kFaQdQkvi1PMQ8UXO10g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752538229; c=relaxed/simple; bh=NExceU280rxT67ncbDAwzVcltQhccGXRdiNx8D/OGwg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=cOjf3abZ13UxXe2iLwd6ctE6IPB3iVSV5zEWgcyyEXHLtu9oRY7dE1GkbMs2ZAfd5JsrEJkp4cbXC4ewomak6veD/uoNQsvNPiS+3oZU2KToEx0fnsCiIrvKZ3wvZbu+JUV4afbyhA1khF0Wm6tRI4/F9ay9WwQUuC5VllnUjNY= 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=DHFgwwOc; arc=fail smtp.client-ip=52.101.57.78 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="DHFgwwOc" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fxP+iso2sdVj8q/XDJvT4lpGgGp76MK19rEm4IlaaXluJnrj0dXoXR3tZdt20NGuFvsgMBeDBtLsXnM02ufxKMDVEhpbb3BdIYM81CXgedkNiDKz/LAgJmvs0M+DzBvxS09/RB5BVhI8GYyFEDSxl5DiBIvicgO86k/DI8NljWZVECB8tFYXGFI4oJWeH8JUxdMAHRix4hZ7F+5NFsWo4HVoYLj9DpBD7s9l7KZf7AvhlSGNFsYC8lvVrCHgmXeu7Y2q0IIDar0ReVYpm5PQyshYlTJE8X5Mhz9WCqscfo9a8LPAWrFf5H6Iz/gHoSFpGI5cVW6YLUhpZpojsSKvag== 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=KvPYRJyGutHucSV48IH6dA329k4nFK56aUeROUio0/s=; b=ooYvfV8MxIXE0rV7/7FhTYH34gqUeq2Islwu40WBu+CREWPZMLXB/WHBHcrmb9oiapLbI8ilMXzHxWsv6KpOjeLpzu7XSJ3YBMexebhSvvQXMBjDNldPGt3i9dQ3ukO2i419pfXm0UOEbNzyfu/Jyc4zZZ9qojrsZarkLMDQBmv+9GU5lzsquv2yKhXicsC2/hmBNeQmgn3HTIULNNAHkZLospe6YOhSI9zjwMaSFa7uDLiK0+UZDX7HFH6/9gFRaKPEH12mB1dM2k5zSt++/q1q4E1MWwJBYA4KrM9nx7SqOdx/zl5/ceKdT24HE4U2+wTPA1mkSWEDWEY+5qRMPw== 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=KvPYRJyGutHucSV48IH6dA329k4nFK56aUeROUio0/s=; b=DHFgwwOctkpD2I/xDto8XyVEQC0qO7nIao7jnbutrGG+AP5WTmkY6EViArn9CycpuU1CSZMK06RfoN6My4m/cP0o4T6THPFnx/ROvBLQiE2N6pMh6nmxnQQevfCLm3d/ORa/BUrq2Jlpj9Ijh0rp87tEhQTLtdWw3g7QfUCaIDA= 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 SJ0PR01MB6239.prod.exchangelabs.com (2603:10b6:a03:29d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8922.32; Tue, 15 Jul 2025 00:10:23 +0000 Received: from BN3PR01MB9212.prod.exchangelabs.com ([fe80::3513:ad6e:208c:5dbd]) by BN3PR01MB9212.prod.exchangelabs.com ([fe80::3513:ad6e:208c:5dbd%4]) with mapi id 15.20.8922.028; Tue, 15 Jul 2025 00:10:23 +0000 From: admiyo@os.amperecomputing.com To: Jeremy Kerr , Matt Johnston , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Adam Young Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Sudeep Holla , Jonathan Cameron , Huisong Li Subject: [PATCH v23 2/2] mctp pcc: Implement MCTP over PCC Transport Date: Mon, 14 Jul 2025 20:10:08 -0400 Message-ID: <20250715001011.90534-3-admiyo@os.amperecomputing.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250715001011.90534-1-admiyo@os.amperecomputing.com> References: <20250715001011.90534-1-admiyo@os.amperecomputing.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SA9PR10CA0008.namprd10.prod.outlook.com (2603:10b6:806:a7::13) 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_|SJ0PR01MB6239:EE_ X-MS-Office365-Filtering-Correlation-Id: 874a2b10-5743-4cb7-3354-08ddc333fe84 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|52116014|366016|1800799024|10070799003; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?cE2jTWzwKVSUQsoqZBz4BZ7g2VJFFn9plxgalNXXmHJ3pd8ZBqjrihuLX0Yr?= =?us-ascii?Q?2+Mi5bj8FoUos9mKqrnn/UCyQ0zgab1pR92A3TmTFF79mCBj7D9umuJ0aAgk?= =?us-ascii?Q?5Uy1bxkSlXWmmLIl+OYCp0nUHyRhBuHs5xHC9fqISfdiuAYHi6Z+gRzP9Qeu?= =?us-ascii?Q?WlGneCrWjxm+zdzNAd/aksDJ3lHvWhW/NYn6J4oboK5iG5ky/Lw8s5LWhfQx?= =?us-ascii?Q?GO4alec7LGCBgJQ7fSQp8VlfrL92tsnhrHE0Kn/Uv+9G1zdT6KAXfbSrug0i?= =?us-ascii?Q?lCIAy/FyBlHSNErLBtS0Njdbm9tLb+jAGd3268iHVKdVCvf6ztvFS3kzfhrG?= =?us-ascii?Q?xeAIAsyclYa348N03CDslVeoRC+wydTpLDBeoWm9QqHQAXRboGkQ7qGVZ9M7?= =?us-ascii?Q?AKxfPzRSg6nOtgIqeE+y0U6BvfHHOQztdTX99Pjad0/V2oKym+t6Y2/pRXYj?= =?us-ascii?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Bec5sZwPCkWFUA49rMvt?= =?us-ascii?Q?1ftgHt4FMjCkmnKXv1PLoOcfWw51NSsd3GuBIChSKz7Iao99ImY0yiN05vYU?= =?us-ascii?Q?c2j4FAMY/7s=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN3PR01MB9212.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(52116014)(366016)(1800799024)(10070799003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?ADU24XxCjucAjiL1nTzFkk+Vq01peZ2baH6gwNIo1esK7tnKIkMdQhUuAtlg?= =?us-ascii?Q?m5HOEdOWE4FQ2/iaNxsHeCgfeTzyebCHat2eEGisCvu0tIy2OmzqVb/sPH8H?= =?us-ascii?Q?UE/lTwF9xD8TcHF8I8Q+96VPYX/c+pXLftQMHL+a0o+nSwrsFYybonOc+gCC?= =?us-ascii?Q?PN1wo7APniTB84xpG6e4dnmW2YpuXT5lr6og7AJLKeGzbUbf7fM+3GpaMSF0?= =?us-ascii?Q?TpEQ4Vj64j+avPVnxPBGWWvq3eLq7XtkqCAUfFoB28XgOvSmnNxGvM9qG5rp?= =?us-ascii?Q?w8RnhjMaWanF0wViH2/4hPBJg/mPKTvyEmyvGrkYdqvuOna8pz2AeUFfNcUt?= =?us-ascii?Q?8JxSNiSLhyWV9CL7WAMjI4Jpc/luuW0g5rDn8O9cBonXlXJo8GK3KySdkUUv?= =?us-ascii?Q?jZlIxplC18QYHkFLPjtNFg6tOp6MDHHpMwak4x5ZXU9FEsmNZ6d9gIVNboLf?= =?us-ascii?Q?BF8nBZQGF62m6617gNgw97XlfY/T3tF+le8EBH6cT2OC+v+d3gSQ+fa6oWzM?= =?us-ascii?Q?iZE4DLWbtb7qgAVA8/jjSEX4js8lwuCL880+2xKfV9VaqFlNqlQtN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DfhmF9ED/OVDpuiAiOD+LqD/7kv2IPBgJGsXjEXgFlB?= =?us-ascii?Q?zg2JNc3DE7WRMv29alh7a5bMekOFmZi8mkFS3CUf1QjCmCljLG1I+WhyfJio?= =?us-ascii?Q?2/IVMNF8l1ZdrOoCFQLK+uJBJhfXH/0+qIYOOmD+VTfp1vbN26+DzhwUTdr1?= =?us-ascii?Q?Rb7z3m+7GuhAEYc1kPe4BKplnKiZrZZ4zEU0CwlUqOKVUptXBVsFIvMZ4m8o?= =?us-ascii?Q?VropBnk1k0PJiOh2/XESZzJsXL4=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 874a2b10-5743-4cb7-3354-08ddc333fe84 X-MS-Exchange-CrossTenant-AuthSource: BN3PR01MB9212.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2025 00:10:23.8576 (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: XYZQ1CarCT961ilvlm33Xj+b6Igizat4dPZ+7cZItNmdDsIqAoxvUOp48KdFic3UcQH62NK7Fw2Qn29biFSpmAyhvopLxPu5SyIMbGgKZ0nmQYjQR0CxPonQPUjELe5J X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR01MB6239 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.0WIP50.pdf MCTP devices are specified via ACPI by entries in DSDT/SDST 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 is also reponsible 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 outging and incoming sk_buffs to match the data buffers with the original sk_buffs. When the Type 3 channel outbox receives a txdone response interrupt, it consumes the outgoing sk_buff, allowing it to be freed. Signed-off-by: Adam Young --- MAINTAINERS | 5 + drivers/net/mctp/Kconfig | 13 ++ drivers/net/mctp/Makefile | 1 + drivers/net/mctp/mctp-pcc.c | 347 ++++++++++++++++++++++++++++++++++++ 4 files changed, 366 insertions(+) create mode 100644 drivers/net/mctp/mctp-pcc.c diff --git a/MAINTAINERS b/MAINTAINERS index 3887d5906786..3939d816657d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14469,6 +14469,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..f69d0237f058 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 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 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..045711a21395 --- /dev/null +++ b/drivers/net/mctp/mctp-pcc.c @@ -0,0 +1,347 @@ +// 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 "../../mailbox/mailbox.h" + +#define MCTP_PAYLOAD_LENGTH 256 +#define MCTP_CMD_LENGTH 4 +#define MCTP_PCC_VERSION 0x1 /* DSP0292 a single version: 1 */ +#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 { + /* 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 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, int size) +{ + struct mctp_pcc_ndev *mctp_pcc_ndev =3D + container_of(c, struct mctp_pcc_ndev, inbox.client); + struct mctp_pcc_mailbox *box =3D &mctp_pcc_ndev->inbox; + struct sk_buff *skb; + + if (size > mctp_pcc_ndev->ndev->mtu) + return NULL; + skb =3D netdev_alloc_skb(mctp_pcc_ndev->ndev, size); + if (!skb) + return NULL; + skb_put(skb, size); + skb->protocol =3D htons(ETH_P_MCTP); + + skb_queue_head(&box->packets, skb); + + return skb->data; +} + +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 mctp_skb_cb *cb; + struct sk_buff *skb; + + mctp_pcc_ndev =3D container_of(c, struct mctp_pcc_ndev, inbox.client); + if (!buffer) { + dev_dstats_rx_dropped(mctp_pcc_ndev->ndev); + return; + } + + skb_queue_walk(&mctp_pcc_ndev->inbox.packets, skb) { + if (skb->data !=3D buffer) + continue; + skb_unlink(skb, &mctp_pcc_ndev->inbox.packets); + 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); + return; + } + pr_warn("Unmatched packet in mctp-pcc inbox packet list"); +} + +static void mctp_pcc_tx_done(struct mbox_client *c, void *mssg, int r) +{ + struct mctp_pcc_mailbox *box; + struct sk_buff *skb; + + box =3D container_of(c, struct mctp_pcc_mailbox, client); + skb_queue_walk(&box->packets, skb) { + if (skb->data =3D=3D mssg) { + skb_unlink(skb, &box->packets); + dev_consume_skb_any(skb); + break; + } + } +} + +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 cpu_to_le32(PCC_SIGNATURE | mpnd->outbox.index); + pcc_header->flags =3D cpu_to_le32(PCC_CMD_COMPLETION_NOTIFY); + memcpy(&pcc_header->command, MCTP_SIGNATURE, MCTP_SIGNATURE_LENGTH); + pcc_header->length =3D cpu_to_le32(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) { + skb_unlink(skb, &mpnd->outbox.packets); + return NETDEV_TX_BUSY; + } + + dev_dstats_tx_add(ndev, len); + return NETDEV_TX_OK; +} + +static const struct net_device_ops mctp_pcc_netdev_ops =3D { + .ndo_start_xmit =3D mctp_pcc_tx, +}; + +static const struct mctp_netdev_ops mctp_netdev_ops =3D { + NULL +}; + +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 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 void mctp_cleanup_netdev(void *data) +{ + struct mctp_pcc_ndev *mctp_pcc_ndev; + struct net_device *ndev =3D data; + + mctp_pcc_ndev =3D netdev_priv(ndev); + drain_packets(&mctp_pcc_ndev->outbox.packets); + drain_packets(&mctp_pcc_ndev->inbox.packets); + + 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) +{ + box->index =3D index; + skb_queue_head_init(&box->packets); + box->chan =3D pcc_mbox_request_channel(&box->client, index); + + box->client.dev =3D dev; + if (IS_ERR(box->chan)) + return PTR_ERR(box->chan); + 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}; + 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; + } + + snprintf(name, sizeof(name), "mctpipcc%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); + spin_lock_init(&mctp_pcc_ndev->lock); + + /* inbox initialization */ + rc =3D mctp_pcc_initialize_mailbox(dev, &mctp_pcc_ndev->inbox, + context.inbox_index); + if (rc) + goto free_netdev; + + mctp_pcc_ndev->inbox.chan->rx_alloc =3D mctp_pcc_rx_alloc; + 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 free_netdev; + + mctp_pcc_ndev->outbox.chan->manage_writes =3D true; + 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; + + /* 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 pcc_header); + 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 mctp_register_netdev(ndev, &mctp_netdev_ops, MCTP_PHYS_BINDING_PCC= ); + if (rc) + goto free_netdev; + + return devm_add_action_or_reset(dev, mctp_cleanup_netdev, ndev); +free_netdev: + free_netdev(ndev); + return rc; +} + +static const struct acpi_device_id mctp_pcc_device_ids[] =3D { + { "DMT0001" }, + {} +}; + +static struct acpi_driver mctp_pcc_driver =3D { + .name =3D "mctp_pcc", + .class =3D "Unknown", + .ids =3D mctp_pcc_device_ids, + .ops =3D { + .add =3D mctp_pcc_driver_add, + }, +}; + +module_acpi_driver(mctp_pcc_driver); + +MODULE_DEVICE_TABLE(acpi, mctp_pcc_device_ids); + +MODULE_DESCRIPTION("MCTP PCC ACPI device"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Adam Young "); --=20 2.43.0