From patchwork Tue Nov 12 17:48:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13872694 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2085.outbound.protection.outlook.com [40.107.21.85]) (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 DE3C7214414; Tue, 12 Nov 2024 17:48:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731433724; cv=fail; b=XhTWHntV8FYQtJNomt6R33MBxtsgbBYmkTI1AD2bJDRrWNfIWTWEJ/oCb15qh4vF2ZmWxtEnSFGLoMzH5z8vQd6+Dk1FStBmoicBMPvx1u7jxrHcaX5f40VAvAchMzHfOMsxSoPhU6qUx5WJSjVrCuW5P1Gmb7HjsHubS3dNBsM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731433724; c=relaxed/simple; bh=61Lz+aGDQkYpdiQf7LVfcFjngzuH5VC8R5EMQvdL0Ao=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=HsgDpI8gMgklKkrYfNhIeV6qKLkVh+iHp5jZOp8GK9dj7BWitjzkCmmgSnkTIjFKxW0o3MIOpt90J6bd5qa/UMb4mrP+hkpNksPxbPWuerRg30qrZ30UkzF4gG36k5dakyQsR7U32ObFe1L9a0XdUWeRQx8ALoLtl+8KKu6/lDw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=h4EMPc5G; arc=fail smtp.client-ip=40.107.21.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="h4EMPc5G" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qBL1lA1iUKa/zM1+ZDwCL8k7JiJ0yFQvcoVL0MeD1z9gpBS/o9j2IvPzVsur9BIIGkC8DmudhbZ+ssTncwaf278ksP/pFxmTZHzfqH0dgwvbjo1ofcOS8pBY5eSY30SGDmTdczzsNLCDav82g5USm7LRZ90WWBHMNzVq6Qja73XchIWQTmNTZF0aauNddkKf/LVybMn32HEAqt/9ZiHz4sB9nScnD8VLtYziXmLZW7cYvwSVoQ3icWaN9buTJWMdXoZWQi3l/nEUPjZftl/BRIbSl6g1KWoIxdBJ/SfHoF8REf6o3qvmsFz5gJgSfsPmQ/+sdqn0pZWhyNPS4Y1ykA== 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=oBHqw5apHMvrrXufyd1Q/VZQPQg6/TA5tygGYqkmzJc=; b=iEMfnG4C9eEBrIC6DEQpluLW51MctiamrXVRoE3kbHVQtxsIOhsLc3c8N0L7jLztk/6BP72JwV69BPVO9nd/fNttnKSb6QAL/w4ZBqTWGYms4av79QRpvXD7Fma2uZhmOwmfs2Vvwi/KqrLpvQVAyuVNq/1i3g1arYOEnTfYD51D6lZ0L3azYW5MxOmTgr6E69MO+lo7cXKFl8tg1Ogn7Nay6uJT5ffiYFtbpDiabPqhPf0/LB6FqZRNOl8C5eIk9rhqpqL5e2rV/TCDD2x1MxPw08S8NKUr4J4XT+5l6blYHh1HCzHOwmiZcd7BhjiC9DeXS0Z0lO7J824xqrJUPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oBHqw5apHMvrrXufyd1Q/VZQPQg6/TA5tygGYqkmzJc=; b=h4EMPc5G/OaGpSPvriP85Yd/7zGBaNLnbBIN0glCiMUpefrZGfhcJnIXyvN/aREknF+RLaQSM5Yaxe0gjSpstFJskg9Uzbd1GrZv3e8AnU38Sp/sy2h7D+SqrbORZ2LBtjkh9htO6o6EbUOeyuSW9tdKkW2T085U+8Dkv7+cWJrBgwprwsTJfYZemkQolf/RNBbkJk2OGH/90tnIj6I/Fj19c88yLLnpzO9FIecF55FjuN1dIPno9ZF/dY0BYwJUcdmh/YUZC8SrZ+dd/xyIaCDADuY2Aq1FEyo0XYnsHnvcvP/BNBugwWW8l9v//ZQHGPMn0oQo9bKe3LTT9ZL5Pw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by AS8PR04MB9510.eurprd04.prod.outlook.com (2603:10a6:20b:44a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17; Tue, 12 Nov 2024 17:48:39 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8137.027; Tue, 12 Nov 2024 17:48:39 +0000 From: Frank Li Date: Tue, 12 Nov 2024 12:48:14 -0500 Subject: [PATCH v6 1/5] PCI: endpoint: Add pci_epc_get_fn() API for customizable filtering Message-Id: <20241112-ep-msi-v6-1-45f9722e3c2a@nxp.com> References: <20241112-ep-msi-v6-0-45f9722e3c2a@nxp.com> In-Reply-To: <20241112-ep-msi-v6-0-45f9722e3c2a@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1731433711; l=3147; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=61Lz+aGDQkYpdiQf7LVfcFjngzuH5VC8R5EMQvdL0Ao=; b=JfBGlLbUICVEhgeq1pCm2JEL5YtsQO+gOFr9hG95EmvmL14CIRu9p//oyfgLDJIvgJx9XO7Ko 5WY02KqrduVAkmrx0gA9rBrV1uF/bcJAWy8H3QdO/CChFUV6On2trZ6 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR03CA0076.namprd03.prod.outlook.com (2603:10b6:a03:331::21) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AS8PR04MB9510:EE_ X-MS-Office365-Filtering-Correlation-Id: 2cbb45f0-b439-4e87-6e5d-08dd03423d84 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?uZ1FM1wbEh+lyRGU1CZXJmbxl9gSMrj?= =?utf-8?q?5bbe94fhPnQCkKGEplv1iqZIpsfaoyN5+CmeG6cjwWj+wAEcqF5DYuZ3XVbMB1ZaK?= =?utf-8?q?ENMUvRgtMMlWmYM3wmnp9kkbi/9CwEGUnEKGyUcg09/UXCr8ObM3fcsG0xqc/7lMa?= =?utf-8?q?rzZLx9mnvisPQKRruwZgDe0kCnvkCpS6F5qJXglRuTGm9wzJpY5IxNvdr4GGuVbHX?= =?utf-8?q?ILIUSuni5EWU/N8KQJ3eR+moiYM4ud46hUOmQBdWvL6T/F6pu02eqdY297HwG6Lmi?= =?utf-8?q?wb/Tyzu1EMHjnvyxwTDykpKz6MHQ5BA1gaeaCpDI59FGFiSwy2dlWd1sgTEIOX/LF?= =?utf-8?q?udfsjxQdowwcvk93lFkAcOZBBerPukKqeYx6ylEtiEW3qEivUNEGPqjpQuHSwBlTq?= =?utf-8?q?9lvxVcu1zcZAD0GipIqv7xVWWaRXUlq94eDaL9XC00PyV04tKzjcTLkIKNAWWE7TO?= =?utf-8?q?u3OExU3Ywy5+sUT5InL7kt7SPb7Ur2YwIeOMTY0QJljcKzjmEhpgXxGJ828UCYkxI?= =?utf-8?q?2RHbRNwhVrgT0gNeyy46UXpkPVaUGh3DSLWyRQOV2eOZf8RhBV0h4ufG5o77MWf0h?= =?utf-8?q?NHyIv9rytESfIt9umQNiciohpZSArHoCzkAVYwHbUrQY08YlV94bP9Q20B6pIq3Dr?= =?utf-8?q?CQyylkWpJDEAOQzwl5sMz9H3CEMh2FbGCzDJdbmpr5ZjaKvv8baHyh+c+JdkL5vOL?= =?utf-8?q?prgpLeJdiqHSVanwPl9o6BwXYLGjBXXxqYa5iGNPs8GtTd7olWS7WyNKoFk24hX/r?= =?utf-8?q?cIddl+BNR8e7UzGVfoj62MJdaHVxmmI/vveovimrwKT2wWFx1oiKyyPFsxFviqsBL?= =?utf-8?q?/atpAZmWqEN+bY42KWLl8sfrmTE5smghWqUgO0PkGpvNxo4/X8WFxw0T9rbrOMGgo?= =?utf-8?q?oH66ouweKyMTe0QWw/4XMnN6OfT9iS8ckJNvrX70lYHnmV6eKYyWcsrmooOYcgv3h?= =?utf-8?q?QW+j+t3aE1zDaG68YsWl1PpI6F/huZyzQOd72svhGVTtMqgfepJ2c2efLuz8VKTkb?= =?utf-8?q?JJ/tQmi/Q91nQ3QeXdZwImhv8UYeUPQTw/b/+Ru4Z3WR1jmkSGMpLd2fiyX21yvca?= =?utf-8?q?wzISbELpu/gxsISo357encb/MRdNzstaYCY8wcMeO4m49eFgdI3Di4fsmyVSmFo4P?= =?utf-8?q?kaHKIPOqwOGo0LEsGP9GtUB8gEKV8xGDzQYiJnKhRSRKqeV9362v3dfZ2AOx4TZLi?= =?utf-8?q?92dPi/2ON2CevOU6zPGGr/0py6LZy1+gNjdhSgOod4BbLCjfl6E5iU0OYiCEnOLC7?= =?utf-8?q?5wmZt7VeDi167NQtbomJZeet8hxaAwAcgzcy9xu3RXgupvh9RAefJ0mA=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(52116014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?uEJH/KOeUiqUacKQh+zca5K0iCxc?= =?utf-8?q?w7vR6pTFj5sQVMd8xDAyJxrSUD6mxe0O3ms8VCqdf/G1PeO8hkeZUF/NaHMpIEdP8?= =?utf-8?q?X6JKrHV0ijl9zgY8p0NDueX9FQm09LC2PI09j/vNe3z44Z39S8+EMTmi1A9rVZgUb?= =?utf-8?q?7NpRsa4G5XKgxWUfsSv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RvCz9xCD0QKvj98zqccvKJBUdAMcaYLXb?= =?utf-8?q?62KOK9hLFNz1iMQnB+L09fp8jpphDbY7sWZiV6Oy0MfOPRaEs6FVou3konipwPDRz?= =?utf-8?q?ICf5i9Xp19PglohwGXDON14bNJxc0Ku6JBuSBhAPsAvbEd0H4bOkQc/KVqhPffmJt?= =?utf-8?q?EwqGi97Cy7vhYPhJdbcXydcTEgTnX/jQrMNJ1nifUqXM3fgylSgCWxC0gzzBVnLhw?= =?utf-8?q?fh29Gt8NiTRiHJ+/t72YQm9X0k2l5Dgnzr3xZ3oM/uF7hz30xOkn3KiOTWgVGqHHH?= =?utf-8?q?nKoIsHBqGoAEagsL5WX6bM6c3xjXgbtMN/w+/sAHkNJuWhI3acYN4YrIFiz5fC2j2?= =?utf-8?q?pK9ChXhB+m7RwhJnXsBrlEfENQzOrVdE8OTEyG4z49VY5QRdzlvoF3yu/hyWApDlT?= =?utf-8?q?SH2WKa5fBqiCCM9iLJZBtTguLEOv8NIclChtUozUrh48VP6rEJH8JrgY=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2cbb45f0-b439-4e87-6e5d-08dd03423d84 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2024 17:48:39.2573 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xQGL0p8n/m5JTwcLA6YgLIT7HH/XFQUKEJUauZjfPOCLMSPgpP1yh/n87DvHHWmcvZxdNTWrZzq7V0JaVxsYhw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB9510 Introduce the pci_epc_get_fn() API, allowing a custom filter callback function to be passed. Reimplement pci_epc_get() using pci_epc_get_fn() with a match name callback. Prepare the codebase for adding RC-to-EP doorbell support. Add DEFINE_FREE(pci_epc_put) to implement scope based auto cleanup. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- change from v3 to v6 - none --- drivers/pci/endpoint/pci-epc-core.c | 23 +++++++++++++++++++++-- include/linux/pci-epc.h | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index bed7c7d1fe3c3..f5538c007678e 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -48,6 +48,11 @@ void pci_epc_put(struct pci_epc *epc) } EXPORT_SYMBOL_GPL(pci_epc_put); +static bool pci_epc_match_name(struct device *dev, void *name) +{ + return strcmp(dev_name(dev), name) == 0; +} + /** * pci_epc_get() - get the PCI endpoint controller * @epc_name: device name of the endpoint controller @@ -56,6 +61,20 @@ EXPORT_SYMBOL_GPL(pci_epc_put); * endpoint controller */ struct pci_epc *pci_epc_get(const char *epc_name) +{ + return pci_epc_get_fn(pci_epc_match_name, (void *)epc_name); +} +EXPORT_SYMBOL_GPL(pci_epc_get); + +/** + * pci_epc_get_fn() - get the PCI endpoint controller + * @fn: callback match filter function, return true when matched + * @param: parameter for callback function fn + * + * Invoke to get struct pci_epc * corresponding to the device name of the + * endpoint controller + */ +struct pci_epc *pci_epc_get_fn(bool (*fn)(struct device *dev, void *param), void *param) { int ret = -EINVAL; struct pci_epc *epc; @@ -64,7 +83,7 @@ struct pci_epc *pci_epc_get(const char *epc_name) class_dev_iter_init(&iter, &pci_epc_class, NULL, NULL); while ((dev = class_dev_iter_next(&iter))) { - if (strcmp(epc_name, dev_name(dev))) + if (!fn(dev, param)) continue; epc = to_pci_epc(dev); @@ -82,7 +101,7 @@ struct pci_epc *pci_epc_get(const char *epc_name) class_dev_iter_exit(&iter); return ERR_PTR(ret); } -EXPORT_SYMBOL_GPL(pci_epc_get); +EXPORT_SYMBOL_GPL(pci_epc_get_fn); /** * pci_epc_get_first_free_bar() - helper to get first unreserved BAR diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index de8cc3658220b..d3d3b8c914614 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -300,7 +300,9 @@ pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features); enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features *epc_features, enum pci_barno bar); struct pci_epc *pci_epc_get(const char *epc_name); +struct pci_epc *pci_epc_get_fn(bool (*fn)(struct device *dev, void *param), void *param); void pci_epc_put(struct pci_epc *epc); +DEFINE_FREE(pci_epc_put, void *, if (!(_T)) pci_epc_put(_T)) int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t base, size_t size, size_t page_size); From patchwork Tue Nov 12 17:48:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13872695 Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2058.outbound.protection.outlook.com [40.107.249.58]) (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 D73E9215035; Tue, 12 Nov 2024 17:48:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.249.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731433728; cv=fail; b=jbYchHgwi3eTjR2UjaWuWDtvAZBJpS6RX2MWON8YRpqPeGUYe4eodZQ72KVFtgDAgExENbbNSmpPJ4rF2fuHwpGHX3wA2QChQh8p9Zo6MV15FoOSFGFsW5X8etOhhmu+OW59klk2H+++1XhXA56L8zEMwFwRh3pd0dsnyVKTYd4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731433728; c=relaxed/simple; bh=YT99E9eq13FEX+qUFaoGejBUqS7EaIaDgacmztfhmnw=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=ODQ0IzlL/jbaFwT3sZZgk3EBpUIvulEmcWIMYurZkI8oyW00FCkaKJl/J8iKvT5EnljZ4cCdXqnyQZ70mmOV/FUtulOFFnvFPPC0lUGhDDjca3KfM7T7mW0brLpd6QfP1DdlFfsD2926ydzzYY7M0/ZVkKp6sowyzrH/+qO1fPA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=Pyrwu7vH; arc=fail smtp.client-ip=40.107.249.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="Pyrwu7vH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KZAjuLdPctdELsZH4lR0hr+bbPx2MAtRFru8O73t1Yap4rMc9LLLeebEBGJ9dWpUtJ52e9G3aqcFai3Xx12PA1SwbIhMpPa6e2HfbIwU2kJwfM0jutS3a1kl+AVJ/cobhU/ZLUovBpNtL0gWV7ffkP6/yuqqjOWSVAUaYRsMG9HN+NzI/51O081+DhaVG8y11NxVXQRm+hGB1F5VJCWzl2NlZHIaJT4IO7prmqKjEbr97sJTIMxJL9sJ/UkdkoAXxGKMDSvfUn1ALn1uT1lTivRtimEFVa9xClDruzOgIpX9m5jFLz1nUtjzu0i/p05PFu8FBBErAkhEy3folbgaaQ== 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=0C1f/pv6sXoxTlSc1BeTk4SRqkS6VfLm5JtkIQZDNKI=; b=HGijjyuYX3EjDmNExNBvLGDqvEHijQdZYIuIsdyBYM+JlwyNyFVvIZf8ekVIFsriFXQVSQ2owOF9ONgNgDV8lTnZwoAoHCnZpAT/TKxRzV2aMJ78NUjR0B4YhIxegU5Ns1j4qPGTiL8ZIe1w+rpn+RpKrudaZ2j2EasYLg27wlmtCbrLf2sTApyPcg4y4l+0WQ7UwiZZNiz3iFgqnQFv1OO9DpAE00m/QhvD/NbkSmvVBIXAPBruFn0esnsq53Snw3der3YDPXIvdLbOmm0KBa3TDYlaPlIbR+MFs8vBGOFoe0frR0YZfNm2c+fBzxXcrbCzEbesc3WCPLfHoK5H3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0C1f/pv6sXoxTlSc1BeTk4SRqkS6VfLm5JtkIQZDNKI=; b=Pyrwu7vHT6SQbsoWn27SSPf+A3Qy9NkOAxMnL0YHWdhmTopBciuLnWZqsIgeXZyX5zoX6zGy+GjrNVy2AeZDEdfHzsoIXmQsc4A1wfvanL0VXb7RbI/3FxWVqnQRjBqETzkFUItpI5Casn+KwKX2pKxzPafnwxeqAYZE8EPMZPNCJrjHLyBYoAPHzK3NNiXbPuoMjygcU2Eh8v22VXPBqYTNje31OJoDsjdT+H0smg2D02CH7M092WhX7c5rclML4cYoabg2vYXDzSzmeEAE1Iu+Sy3wB0etJCL7ak4iQWwY993jWJWrub2IaWi2avjlMlkDB2sRkSkelO0eRuwZyg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by AS8PR04MB9510.eurprd04.prod.outlook.com (2603:10a6:20b:44a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17; Tue, 12 Nov 2024 17:48:43 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8137.027; Tue, 12 Nov 2024 17:48:43 +0000 From: Frank Li Date: Tue, 12 Nov 2024 12:48:15 -0500 Subject: [PATCH v6 2/5] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Message-Id: <20241112-ep-msi-v6-2-45f9722e3c2a@nxp.com> References: <20241112-ep-msi-v6-0-45f9722e3c2a@nxp.com> In-Reply-To: <20241112-ep-msi-v6-0-45f9722e3c2a@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1731433711; l=6297; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=YT99E9eq13FEX+qUFaoGejBUqS7EaIaDgacmztfhmnw=; b=3G7wSUQ8lVrRXb76K5hYxWOK7cOGMX6K7i9qKqWPomG9g6fOex46BZ9Dk8QR0E7s+K0JR3lpL +lTN1oCDqjmCB11vht+gh8gERaJydPQKuyuwjLxlpjt/DWiNYxfSNRh X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR03CA0076.namprd03.prod.outlook.com (2603:10b6:a03:331::21) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AS8PR04MB9510:EE_ X-MS-Office365-Filtering-Correlation-Id: 41a15fc5-a550-43b7-07ae-08dd03423fc7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?45tbRQNyCrI4Mm3elpSSFj7zx5cE9mP?= =?utf-8?q?7jo/VYTUs/EsqoTaVtXLr8QyFEp6WoW/weJ9AxrZytglXRp47+TqdwzBVKrgSXiOq?= =?utf-8?q?T1WiB1a7nc0I/H3ID51B8iicR3BNGzZJKCyv5gC611oREDzh4sVlWMNOHzNcny7yw?= =?utf-8?q?EGuoEynRQgEZZ94vkJ+SX0lkYaBHb39aeMxjLihoGr/ebxy2bwCHLOJuWSjHGAUfL?= =?utf-8?q?ZjNE8kl1+ubJFBLth/e+Zya7mkc4Qik5qyvVa0Jvo3rw5LuP+aGA/ZZtCOjm9sgw0?= =?utf-8?q?QiG3zYaZZiHAxpHk5YUuVEmlYkFfWWlA1narIs250+QlJrJLjXleu9TJ9eKWKHxN9?= =?utf-8?q?jtcAbWwvgpdf3Y3mk3Qy7xh4bkPYRYLlZOmg514rik7fCXsTCxcE0RE9OceKCI/zY?= =?utf-8?q?1UxRf8d+w5SUbWMqvX+stXNZWqE+H576VN/l5h1FQ5thgc0KT5T3jfssU8EK3LLPY?= =?utf-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255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(52116014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?3t50EB9K2xyYA7rN0OZJIXpRo4Bg?= =?utf-8?q?FDiDg4W0CLW9r5ih9ysX44hQ5xlklrUFUP3rcHXTRhBM+OTXn+FTApmujlD2cKe/J?= =?utf-8?q?IWWTa80IBzy1BA9Y2rcZggu29rlzg187y8NcprN/b0xhB6N//sPQuY5yVx9tQr4na?= =?utf-8?q?hFzbgPM+RV8KCSJ5UPDVvaQWsiJkrPFpbZ3GvQF7tSxMbblmwMphyi7S739zunr/C?= =?utf-8?q?kMaTSdKvLn0NOGsmTMQRyqaxMMQoBVlg9LaFm7sGv/agLs42odC5vqacHat6tdzGP?= =?utf-8?q?tG30/oMzvd61LLqj+asUUKVacX5olhUzC5xGfCI10cEm2RlrVnNMfsHuPj95NquUw?= =?utf-8?q?zy0kdMZZ0oqkPKmOOvtVGMuJB4wYiLA+mYBTWkW6FmuRqh0DTzYP8jrObtEwpqmuF?= =?utf-8?q?voaTs/1fduWW9MurnZ4/TuFQsAIbd7y2km0poay8XF8+uPAKuQfedlDUSt1X2n/ix?= =?utf-8?q?9yEHlPeysRT6tBZVfUsbUbAndJrQ6dqO0xlIfy5+9N/tJ01eA+xY3QchzRB7ueRWw?= =?utf-8?q?KuCaSvTNw6C6fevD8ChbCl4P+Dr1gUSsCfZKgvDAJCVlio80oCFXBGQg5nemhRt/I?= =?utf-8?q?LntgmeETQ82JO3TkrH64TNw8OBx1GjeVWwXISSNljT8zissp80TPXfPXGRe2Mq++o?= =?utf-8?q?LL873WzGB0T0/XngFyuoRGXOufSgs09ozvgiRXSlaHZH4wgtygpux4KUdRXvMwvEi?= =?utf-8?q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Tenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2024 17:48:43.0516 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1QZiWkSYEZ/Qq1DiMO0HLyfBes9+5ifUZtFYwHkhXqUHJER6OwZk27hOgUj9c+5LBd8JSvSrwvxaL0IBLwjdzQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB9510 Doorbell feature is implemented by mapping the EP's MSI interrupt controller message address to a dedicated BAR in the EPC core. It is the responsibility of the EPF driver to pass the actual message data to be written by the host to the doorbell BAR region through its own logic. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- change from v5 to v6 -none Change from v4 to v5 - Remove request_irq() in pci_epc_alloc_doorbell() and leave to EP function driver, so ep function driver can register differece call back function for difference doorbell events and set irq affinity to differece CPU core. - Improve error message when MSI allocate failure. Change from v3 to v4 - msi change to use msi_get_virq() avoid use msi_for_each_desc(). - add new struct for pci_epf_doorbell_msg to msi msg,virq and irq name. - move mutex lock to epc function - initialize variable at declear place. - passdown epf to epc*() function to simplify code. --- drivers/pci/endpoint/Makefile | 2 +- drivers/pci/endpoint/pci-ep-msi.c | 99 +++++++++++++++++++++++++++++++++++++++ include/linux/pci-ep-msi.h | 15 ++++++ include/linux/pci-epf.h | 16 +++++++ 4 files changed, 131 insertions(+), 1 deletion(-) diff --git a/drivers/pci/endpoint/Makefile b/drivers/pci/endpoint/Makefile index 95b2fe47e3b06..a1ccce440c2c5 100644 --- a/drivers/pci/endpoint/Makefile +++ b/drivers/pci/endpoint/Makefile @@ -5,4 +5,4 @@ obj-$(CONFIG_PCI_ENDPOINT_CONFIGFS) += pci-ep-cfs.o obj-$(CONFIG_PCI_ENDPOINT) += pci-epc-core.o pci-epf-core.o\ - pci-epc-mem.o functions/ + pci-epc-mem.o pci-ep-msi.o functions/ diff --git a/drivers/pci/endpoint/pci-ep-msi.c b/drivers/pci/endpoint/pci-ep-msi.c new file mode 100644 index 0000000000000..7868a529dce37 --- /dev/null +++ b/drivers/pci/endpoint/pci-ep-msi.c @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * PCI Endpoint *Controller* (EPC) MSI library + * + * Copyright (C) 2024 NXP + * Author: Frank Li + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static bool pci_epc_match_parent(struct device *dev, void *param) +{ + return dev->parent == param; +} + +static void pci_epc_write_msi_msg(struct msi_desc *desc, struct msi_msg *msg) +{ + struct pci_epc *epc __free(pci_epc_put) = NULL; + struct pci_epf *epf; + + epc = pci_epc_get_fn(pci_epc_match_parent, desc->dev); + if (!epc) + return; + + /* Only support one EPF for doorbell */ + epf = list_first_entry_or_null(&epc->pci_epf, struct pci_epf, list); + + if (epf && epf->db_msg && desc->msi_index < epf->num_db) + memcpy(&epf->db_msg[desc->msi_index].msg, msg, sizeof(*msg)); +} + +static void pci_epc_free_doorbell(struct pci_epc *epc, struct pci_epf *epf) +{ + guard(mutex)(&epc->lock); + + platform_device_msi_free_irqs_all(epc->dev.parent); +} + +static int pci_epc_alloc_doorbell(struct pci_epc *epc, struct pci_epf *epf) +{ + struct device *dev = epc->dev.parent; + u16 num_db = epf->num_db; + int i = 0; + int ret; + + guard(mutex)(&epc->lock); + + ret = platform_device_msi_init_and_alloc_irqs(dev, num_db, pci_epc_write_msi_msg); + if (ret) { + dev_err(dev, "Failed to allocate MSI, may miss 'msi-parent' at your DTS\n"); + return -ENOMEM; + } + + for (i = 0; i < num_db; i++) + epf->db_msg[i].virq = msi_get_virq(dev, i); + + return 0; +}; + +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 num_db) +{ + struct pci_epc *epc = epf->epc; + void *msg; + int ret; + + msg = kcalloc(num_db, sizeof(struct pci_epf_doorbell_msg), GFP_KERNEL); + if (!msg) + return -ENOMEM; + + epf->num_db = num_db; + epf->db_msg = msg; + + ret = pci_epc_alloc_doorbell(epc, epf); + if (ret) + kfree(msg); + + return ret; +} +EXPORT_SYMBOL_GPL(pci_epf_alloc_doorbell); + +void pci_epf_free_doorbell(struct pci_epf *epf) +{ + struct pci_epc *epc = epf->epc; + + pci_epc_free_doorbell(epc, epf); + + kfree(epf->db_msg); + epf->db_msg = NULL; + epf->num_db = 0; +} +EXPORT_SYMBOL_GPL(pci_epf_free_doorbell); diff --git a/include/linux/pci-ep-msi.h b/include/linux/pci-ep-msi.h new file mode 100644 index 0000000000000..f0cfecf491199 --- /dev/null +++ b/include/linux/pci-ep-msi.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * PCI Endpoint *Function* side MSI header file + * + * Copyright (C) 2024 NXP + * Author: Frank Li + */ + +#ifndef __PCI_EP_MSI__ +#define __PCI_EP_MSI__ + +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 nums); +void pci_epf_free_doorbell(struct pci_epf *epf); + +#endif /* __PCI_EP_MSI__ */ diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index 18a3aeb62ae4e..5374e6515ffa0 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -12,6 +12,7 @@ #include #include #include +#include #include struct pci_epf; @@ -125,6 +126,17 @@ struct pci_epf_bar { int flags; }; +/** + * struct pci_epf_doorbell_msg - represents doorbell message + * @msi_msg: MSI message + * @virq: irq number of this doorbell MSI message + * @name: irq name for doorbell interrupt + */ +struct pci_epf_doorbell_msg { + struct msi_msg msg; + int virq; +}; + /** * struct pci_epf - represents the PCI EPF device * @dev: the PCI EPF device @@ -152,6 +164,8 @@ struct pci_epf_bar { * @vfunction_num_map: bitmap to manage virtual function number * @pci_vepf: list of virtual endpoint functions associated with this function * @event_ops: Callbacks for capturing the EPC events + * @db_msg: data for MSI from RC side + * @num_db: number of doorbells */ struct pci_epf { struct device dev; @@ -182,6 +196,8 @@ struct pci_epf { unsigned long vfunction_num_map; struct list_head pci_vepf; const struct pci_epc_event_ops *event_ops; + struct pci_epf_doorbell_msg *db_msg; + u16 num_db; }; /** From patchwork Tue Nov 12 17:48:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13872696 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2062.outbound.protection.outlook.com [40.107.20.62]) (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 4C595215C68; Tue, 12 Nov 2024 17:48:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731433732; cv=fail; b=j5T/XHnMpMJio6LwciTLNKdYgzfX1iryDj12El1lvD/DBJrE8XtWSLGvYBpLjmz5C1nnBCvE1ubhlhlro0uwGDXsktGPvunLr7y9LLeFzuTy69EuruuaDHOarn2/MKgm/3KsJ1XWtWWKoII3Ryf74npI6wpM3Z2h8sWcmmuZjHM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731433732; c=relaxed/simple; bh=ZboQ2BLdOqWIjNgy+b+PZ+LgoTnTNET8wgnkrAQY6wg=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=g30GJpfM8EajFa3eUY4jI/oKa0v7Xnjy4f91d8ZBBaab5VlBRlx85UoUFNhmyzhCUBTHtb3RPYNP1kPf1TzivbCoiBMwdIvZmkvsIH+tTX2dkEyVLe7awZvPtmgBNW1Bg/VOGs871vnRdbuxpZFgXlpz+0DxDO1WUORKAUHcW0k= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=YO+qyqiK; arc=fail smtp.client-ip=40.107.20.62 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="YO+qyqiK" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DpafnaNq1thQMsohp95tWbTl8RfjvJbMzImZSnAhaWaBpzGwZDVTUUUuwuox6bd2kZh13e/a4wXdRr96DR9C3Tr6S3H4sXrCFmWH8Yi6tnFJ1Sh7pn6fGH52hSwPLAzloCnNUbzD6TBptW4iAUq3/4dffRePtpIplq8uhjUxkdE62IL6YbHPE2emUhd8A7wjyBecwEjaJxILlc/YRo410+IRxT5z+h44A9lPX869lOGLH21b0T1B8mTDDTSKOKLnwedFpViMB2ErzV71NezVTBbnOQd9A0s+M9PfXybAp5SpwUaU/vTz0LKomFyQOEXjG8g3L3Bn3eitqQb52vxXzA== 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=RbS6BZ0dBH0t98ywhMYkZJpXtEPbuws6K5dUXf7jGA4=; b=UF5Nl4qNYqh2q7vNaG7xuPil3GlMGPLjy28ioMQTE9UZFL+hA5EvYxIQIK8ZDYqVuVmHQeN2xDUtEaEmjr5iUYpUTuErd8q+xvEd3aabtcy4ZwPgAlD5cnksjU3DZQkojm/WLNB+E96bN5bdytRHq9AIof7Xu2fNfdgSmgSkI+QbQgsVlAoWWMP912AfcmiM0tpqBH7Qcfxa2KW27ySi8Iu4jH1R12ZEe6dQm+4Kb+nOcaSBd1J9XG8xRMcOdPLYWIdhcBxJx2CfT0/TwYv+e2ma7u4LXDSHJQwNeIxdZr6M34vKXcZ3506UDCPjR33WThdW3xMsDdWRtdZk93DTLQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RbS6BZ0dBH0t98ywhMYkZJpXtEPbuws6K5dUXf7jGA4=; b=YO+qyqiKcHnfwqSj2N2FAe0+ZMKcw4DP8N+OIMgF7E5tjHou7CWNGZTHcvsIPM5EzC0ssbeE/3gvf3YQW85/JI9vCDQuXTarFHsA8PcqKoeZKUU+DAWN+ImNn48qxRl1neAUR2cvt1QkjO6XvPS/kJQlbbdmj59ntlLexpHaSVlG0x2JTkJJYyk2LwOjZea6HYYEWNGOreR7GEDC4O84MyZSgY9fpP9dFS3vowpWlNlgeL+b5wTvImf4QuPGgS6LWUldDy1+8hKzHq3zSNm0avSv1ZYL5yWsoqQmQbd17Wkyy3+O0AhSrZE7gx5CIvqIAB6bCMx2wXlbk0j7EttICA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by AS8PR04MB9510.eurprd04.prod.outlook.com (2603:10a6:20b:44a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17; Tue, 12 Nov 2024 17:48:47 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8137.027; Tue, 12 Nov 2024 17:48:47 +0000 From: Frank Li Date: Tue, 12 Nov 2024 12:48:16 -0500 Subject: [PATCH v6 3/5] PCI: endpoint: pci-epf-test: Add doorbell test support Message-Id: <20241112-ep-msi-v6-3-45f9722e3c2a@nxp.com> References: <20241112-ep-msi-v6-0-45f9722e3c2a@nxp.com> In-Reply-To: <20241112-ep-msi-v6-0-45f9722e3c2a@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1731433711; l=8063; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=ZboQ2BLdOqWIjNgy+b+PZ+LgoTnTNET8wgnkrAQY6wg=; b=ELGVxL8Z2myYje4lYOAdqm3c4pSGwfuVY6xoMVvHgB1SUJAjTg3fok7nhgoXncXra867E0pno eqJtYjV0/cFCh9iiUyCSfBzDCNq4kalulBiksXNdbKbtqVmcLVsrju8 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR03CA0076.namprd03.prod.outlook.com (2603:10b6:a03:331::21) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AS8PR04MB9510:EE_ X-MS-Office365-Filtering-Correlation-Id: e412afbc-5244-42e4-8986-08dd03424244 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?gcctEaBDicmvmhDUE+K4ZHtje0TZg4J?= =?utf-8?q?0VMzeNpNMC32c0KTOnTkW6z28gpvy/WfQvnw0YPGe1kla6CxEdgUjAdOSIorf8PW3?= =?utf-8?q?52M4CGTEhQLEAwHky+iXd/eDfk5lJfP0iWrKvviQbF39JYyfrXkrw3ZO4LeQX19a/?= =?utf-8?q?Sgsf3OaOPlFnEI/+8ZEEaGA/pNgvjhxgvh9yzFc/QwF2mjnkjVJZ6k9S1JSlDS96U?= =?utf-8?q?F0rgUVkUA/UYKdm1NhJb6NglAL1BRWFATr+8Jqq7ZJ2FJtL2ONbMiMY9P9FAq98Tj?= =?utf-8?q?ii28IQUzlz307TUrBkGEj3lOCebvD0lu1aSkcNzYZmA0wvWqni0pZyOphwh29ygrg?= =?utf-8?q?F/+rbtld6zjEu7YrxsQwJiZqC/dqYY7ZPLxWn1DCzAZvDC9LWs4YLJOuGd6nKzfWH?= =?utf-8?q?j2vumbGiv61A+y3vV5vi9n2BDs65+E3saGFfnCaQZpS/qXpPtCKI6lITEsPcVUWvQ?= =?utf-8?q?X/BNmLHVInM1c4f5pSnG4SnprelnVZW1M8a6jh8vorAlBjsQlMm29bsvvOhgu55d/?= =?utf-8?q?U0bhp6YQyaLAbjCBzi863zfrLxDuUYEj4VvKvAZnBPMJ74r/xWFbUPz88zwK+we+t?= =?utf-8?q?ARKCssmvJPQH/HEREvqb+vS0n6YntlAMG0GqM8NYlaoxGM9qhv1kqcDIvxkn6w5S+?= =?utf-8?q?UZ1ejPf31kC2oAirXVE1hAB/f5Srcq/HeXh0NBVenkgDwr9J0Ibeqn1Z+F5X4jMS+?= =?utf-8?q?cQirDkdqVk6D+amFj7qMsQay4IvsDPkRJJnwiPw5Xin9q/gWeO9sJY/qwnDh5wJuk?= =?utf-8?q?yADfpUH093LJGFgomsc6Nkxl68NaVv6DbrtsPe3oBGulvSQmbJWKre6GMBMaMO5iz?= =?utf-8?q?mzjKuMBg+d7g8lnf24BOZvCo4Xpk/ZzeYL4OddMIYjjffiS+R+OjP+cisA+LlQhdL?= =?utf-8?q?ze4yEdpLRrpej97lhXFtsGhXOGlJwF0yoBxYvuKigzzcMyOfkwf84xn3reA/vS0do?= =?utf-8?q?kNQY7p2HmsXxoOZbJ6OuSKKT+JNN1TLWex7usYx5R3k38IblleTtaWUVvPKnhBcOy?= =?utf-8?q?NsNqa6/dnq1W02gTGfCs42IZ1ybDK214xhoilhwiUxICKiGGDBOumQXg+r04llIbR?= =?utf-8?q?Hg8fq95BZRxofwDMuIO7nxLhWYkgzPPvjOZkpC7DYvPoOY0ZBoc4JwXpzEwgIWEId?= =?utf-8?q?DehR/Dlh5dqG0UCLi/svaWO+YPF7vVKtDizqKmpg9ORToAPf/usRTVIfJbHGe7PfP?= =?utf-8?q?UY2l1QvQd1t/VCkUpsYtRPfvJOpG3VndLrglQEm1jTVIT9XA+r02vRhXUyeze9yx6?= =?utf-8?q?ZnuCsn6Jyc8eQkergaFRx3qpCZlE0HJOrud1VkA6DeKm8YlXO1NFS/uA=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(52116014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?PG5Xz7nbtaSruXpoW9XmYFVRRhGv?= =?utf-8?q?8rk+DupUCKm2mu4LmZOlHtlzRho3Wwb2eNSI1Pcqu7do6Yum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M4LWWRbYMAiJAfRhRfUA?= =?utf-8?q?t4Zn+kjmwsEFv893rZuPnsLLrZQxMjlIGHZqdQGlllp/iTbOvhhtwbR858wD8pGLf?= =?utf-8?q?thXRqRdaemoJHLucvIw+fiEO1r3gtd3S1m6HqyJwmy9VC5hayyKer6vvmCnEVEFH1?= =?utf-8?q?rnrfURUyZqEfc9v30x7ktKojUEq4hSz/CIavQV9hF3FjJeJCFGWUBFg6hBlKrcCOd?= =?utf-8?q?gjGEERlU76mph9K35VhC7Vt7pZ7wlUxdaVSlWlT42D5pM2XJq8kbpGSW2fY2MSeSZ?= =?utf-8?q?qPQK6eijfNYT4+S4jQY8MElLwCCIpKDfy6uxy3akecF1rLSlTvD3MtnQiof8Df+Eu?= =?utf-8?q?fkDGKMfc6XjHaByLnyAufj4ZjOHaECtNIGwhFdvg+4NVLbqDs17EyNHOUES1VkS9N?= =?utf-8?q?qBLov4qmaNoCbZNxXbYLfnhN/Ceemmv1JU91SQ9NTVZrp+0g42fHBgtdmj9q7bL7l?= =?utf-8?q?t1VzMSaV48AE2tc7JO8kAOXMXw+G/euqiuB1+xNxJyb8Tr8jUpFvLSdPZUgyvlB1w?= =?utf-8?q?qwAOQ6VBER0nMwtNNCqGbPsmv93oUnOpg7sJ64LEaoZpHj3B5t0Ld1zg=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e412afbc-5244-42e4-8986-08dd03424244 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2024 17:48:47.2226 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /InclPP/mKOKVeZ2bSG2d9uXwWAVerj/8vZEhBBFsQZ3Azjz4bkDtQn7Y4AcU89t00Ns62SLKHjYy8xDoC0uUg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB9510 Add three registers: doorbell_bar, doorbell_addr, and doorbell_data, along with doorbell_done. Use pci_epf_alloc_doorbell() to allocate a doorbell address space. Enable the Root Complex (RC) side driver to trigger pci-epc-test's doorbell callback handler by writing doorbell_data to the mapped doorbell_bar's address space. Set doorbell_done in the doorbell callback to indicate completion. To avoid broken compatibility, add new command COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. Host side need send COMMAND_ENABLE_DOORBELL to map one bar's inbound address to MSI space. the command COMMAND_DISABLE_DOORBELL to recovery original inbound address mapping. Host side new driver Host side old driver EP: new driver S F EP: old driver F F S: If EP side support MSI, 'pcitest -B' return success. If EP side doesn't support MSI, the same to 'F'. F: 'pcitest -B' return failure, other case as usual. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- Change from v5 to v6 - rename doorbell_addr to doorbell_offset Chagne from v4 to v5 - Add doorbell free at unbind function. - Move msi irq handler to here to more complex user case, such as differece doorbell can use difference handler function. - Add Niklas's code to handle fixed bar's case. If need add your signed-off tag or co-developer tag, please let me know. change from v3 to v4 - remove revid requirement - Add command COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. - call pci_epc_set_bar() to map inbound address to MSI space only at COMMAND_ENABLE_DOORBELL. --- drivers/pci/endpoint/functions/pci-epf-test.c | 129 ++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index ef6677f34116e..2d05ab5e4ac6a 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -11,12 +11,14 @@ #include #include #include +#include #include #include #include #include #include +#include #include #define IRQ_TYPE_INTX 0 @@ -29,6 +31,8 @@ #define COMMAND_READ BIT(3) #define COMMAND_WRITE BIT(4) #define COMMAND_COPY BIT(5) +#define COMMAND_ENABLE_DOORBELL BIT(6) +#define COMMAND_DISABLE_DOORBELL BIT(7) #define STATUS_READ_SUCCESS BIT(0) #define STATUS_READ_FAIL BIT(1) @@ -39,6 +43,11 @@ #define STATUS_IRQ_RAISED BIT(6) #define STATUS_SRC_ADDR_INVALID BIT(7) #define STATUS_DST_ADDR_INVALID BIT(8) +#define STATUS_DOORBELL_SUCCESS BIT(9) +#define STATUS_DOORBELL_ENABLE_SUCCESS BIT(10) +#define STATUS_DOORBELL_ENABLE_FAIL BIT(11) +#define STATUS_DOORBELL_DISABLE_SUCCESS BIT(12) +#define STATUS_DOORBELL_DISABLE_FAIL BIT(13) #define FLAG_USE_DMA BIT(0) @@ -74,6 +83,9 @@ struct pci_epf_test_reg { u32 irq_type; u32 irq_number; u32 flags; + u32 doorbell_bar; + u32 doorbell_offset; + u32 doorbell_data; } __packed; static struct pci_epf_header test_header = { @@ -642,6 +654,63 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, } } +static void pci_epf_enable_doorbell(struct pci_epf_test *epf_test, struct pci_epf_test_reg *reg) +{ + enum pci_barno bar = reg->doorbell_bar; + struct pci_epf *epf = epf_test->epf; + struct pci_epc *epc = epf->epc; + struct pci_epf_bar db_bar; + struct msi_msg *msg; + u64 doorbell_addr; + u32 align; + int ret; + + align = epf_test->epc_features->align; + align = align ? align : 128; + + if (epf_test->epc_features->bar[bar].type == BAR_FIXED) + align = max(epf_test->epc_features->bar[bar].fixed_size, align); + + if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + msg = &epf->db_msg[0].msg; + doorbell_addr = msg->address_hi; + doorbell_addr <<= 32; + doorbell_addr |= msg->address_lo; + + db_bar.phys_addr = round_down(doorbell_addr, align); + db_bar.barno = bar; + db_bar.size = epf->bar[bar].size; + db_bar.flags = epf->bar[bar].flags; + db_bar.addr = NULL; + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &db_bar); + if (!ret) + reg->status |= STATUS_DOORBELL_ENABLE_SUCCESS; +} + +static void pci_epf_disable_doorbell(struct pci_epf_test *epf_test, struct pci_epf_test_reg *reg) +{ + enum pci_barno bar = reg->doorbell_bar; + struct pci_epf *epf = epf_test->epf; + struct pci_epc *epc = epf->epc; + int ret; + + if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) { + reg->status |= STATUS_DOORBELL_DISABLE_FAIL; + return; + } + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &epf->bar[bar]); + if (ret) + reg->status |= STATUS_DOORBELL_DISABLE_FAIL; + else + reg->status |= STATUS_DOORBELL_DISABLE_SUCCESS; +} + static void pci_epf_test_cmd_handler(struct work_struct *work) { u32 command; @@ -688,6 +757,14 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) pci_epf_test_copy(epf_test, reg); pci_epf_test_raise_irq(epf_test, reg); break; + case COMMAND_ENABLE_DOORBELL: + pci_epf_enable_doorbell(epf_test, reg); + pci_epf_test_raise_irq(epf_test, reg); + break; + case COMMAND_DISABLE_DOORBELL: + pci_epf_disable_doorbell(epf_test, reg); + pci_epf_test_raise_irq(epf_test, reg); + break; default: dev_err(dev, "Invalid command 0x%x\n", command); break; @@ -822,6 +899,18 @@ static int pci_epf_test_link_down(struct pci_epf *epf) return 0; } +static irqreturn_t pci_epf_test_doorbell_handler(int irq, void *data) +{ + struct pci_epf_test *epf_test = data; + enum pci_barno test_reg_bar = epf_test->test_reg_bar; + struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + + reg->status |= STATUS_DOORBELL_SUCCESS; + pci_epf_test_raise_irq(epf_test, reg); + + return IRQ_HANDLED; +} + static const struct pci_epc_event_ops pci_epf_test_event_ops = { .epc_init = pci_epf_test_epc_init, .epc_deinit = pci_epf_test_epc_deinit, @@ -921,12 +1010,46 @@ static int pci_epf_test_bind(struct pci_epf *epf) if (ret) return ret; + ret = pci_epf_alloc_doorbell(epf, 1); + if (!ret) { + struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + struct msi_msg *msg = &epf->db_msg[0].msg; + u32 align = epc_features->align; + u64 doorbell_addr; + enum pci_barno bar; + + bar = pci_epc_get_next_free_bar(epc_features, test_reg_bar + 1); + + ret = request_irq(epf->db_msg[0].virq, pci_epf_test_doorbell_handler, 0, + "pci-test-doorbell", epf_test); + if (ret) { + dev_err(&epf->dev, + "Failed to request irq %d, doorbell feature is not supported\n", + epf->db_msg[0].virq); + return 0; + } + + align = align ? align : 128; + + if (epf_test->epc_features->bar[bar].type == BAR_FIXED) + align = max(epf_test->epc_features->bar[bar].fixed_size, align); + + doorbell_addr = msg->address_hi; + doorbell_addr <<= 32; + doorbell_addr |= msg->address_lo; + + reg->doorbell_offset = doorbell_addr & (align - 1); + reg->doorbell_data = msg->data; + reg->doorbell_bar = bar; + } + return 0; } static void pci_epf_test_unbind(struct pci_epf *epf) { struct pci_epf_test *epf_test = epf_get_drvdata(epf); + struct pci_epf_test_reg *reg = epf_test->reg[epf_test->test_reg_bar]; struct pci_epc *epc = epf->epc; cancel_delayed_work_sync(&epf_test->cmd_handler); @@ -934,6 +1057,12 @@ static void pci_epf_test_unbind(struct pci_epf *epf) pci_epf_test_clean_dma_chan(epf_test); pci_epf_test_clear_bar(epf); } + + if (reg->doorbell_bar > 0) { + free_irq(epf->db_msg[0].virq, epf_test); + pci_epf_free_doorbell(epf); + } + pci_epf_test_free_space(epf); } From patchwork Tue Nov 12 17:48:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13872697 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2062.outbound.protection.outlook.com [40.107.20.62]) (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 BA79D216DFB; Tue, 12 Nov 2024 17:48:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731433734; cv=fail; b=htZFLWRGfou3e/d6SA68VoTsz2Ny6IMxnRNWDZAyVvhS24/4v2qTVpCiHYI+pMSlxFLnBDwBCLtLslH+OlDRh9gZM5qQQcsKz5vC2md3A/U0ns8Pw+4BmsUP9yIQbT+VvikLr0HZ9xX4skGob0B0p7bKZLs8j7ypmGwSfpd0wMw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731433734; c=relaxed/simple; bh=mRSIYGyE7Zx5MR9tyPF4Gn3e1jwej2qgCm7SNors/a4=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=F2pscnVTJXdaluBAyiYCuFSH5EllqepwkPdgS+1WhtxQNxI+rxJPUKddaDbrKdDb23N3oH3l+PVHJ1nraHZ0L3cOFcdW/LNZsFjATl6VHdp1dBJoVPFxiAXMwKcahn8Y2YHhymXlj7DKFzryVffqw8F0vldB35rg/XnH99N+1uQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=C6fwcaBW; arc=fail smtp.client-ip=40.107.20.62 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="C6fwcaBW" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=slGLSFIbO3nElqxOyFr0zMQFg4iRlVxXDGq5crgl9rFkjliRbVpGpqyJHg5ZMWSZUTQ0mkI8LYlCStxRmn/x2ZaGq7ENry5Clky05D4a/xYDWJVzYHqnM1FG1mHYUov3c3oJHlChHxINTJDcbz32vt3iobWidL+iZ2FnGpCoeRQppDbvDoGa7krb3g4bknCgbjjeL685p7PMBNOx01cpaYNhHxQGRmUy319/74/G3PfK+w2SASpxriuO9jBeG6sxzWd0i0VI0EiItON4GpQo6jtke2BXzsrCIHUiRFNxiAHSE7xlHVrXvSZ8dCsaU8Aa03Dk3Fmotzrt/wzfO+1wjA== 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=FqrRfjNvc6E0BC0Bxoerwxqq9oC9JL7vqGF8/bfEknY=; b=U3F1jFOOIYhcJ3zIO2p73x3j0uekH8NA9TK6cTGom963YsKFN6fLf2BzXKciOFGFaya6maW6mk7MXuzroQsjHnacKPXTTZt3Q1tVZuMCq/FfrXyiujiV3C4fu6F5JsFEEjPJKF2UHOWDJv+6KtV2jBRwaNgx2q6SBwLbmGmQWzi1JxMJa6iSL+PGB/iMlkQ/kxOlF1mSCkVb/0v5OagH/lf16h7XfjoVuPmgOLmAdjFp8E1Jf7P+cWpgwoNvm1SPaV9O9ma8bwHWeAbDxOtdaQ2UQzSHfMJLNkdn2ZTV5CP3IhZmw1/aesjTHkIF9R5XeXqDoKY5Kfox33+2X6fWEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FqrRfjNvc6E0BC0Bxoerwxqq9oC9JL7vqGF8/bfEknY=; b=C6fwcaBW0uMOw+VKuR+/JLOBV0WFVlDiv1es9PMpUFiD+tJxwJ3jtZgCU2t3cyyiX8i/1bbjlPZHqQ3ZsLlycgONAhpVIfjmFMrghnhsjHj8jG/L5lgU1cPfEEd9P7zqm95BgRsCtonRpF5mx0bVjRdoIwP/17XqEz+1OgMC3Go9ompAjcI1xNLfyA/jnZIDuuQNrfG6XjnNcra2EHzq9XyOk2WQu8/pMSW6kTfLFmIkgfpsbcfP4taFBUaE/W9dNvUj/UmBz6cLpm7gsKvQz9hktriPLtx7iJq9pifilH+dNKOOcsCHv+LjOMB8DqeCyA3r1lVdrE3xQYZe3lPmgw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by AS8PR04MB9510.eurprd04.prod.outlook.com (2603:10a6:20b:44a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17; Tue, 12 Nov 2024 17:48:51 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8137.027; Tue, 12 Nov 2024 17:48:51 +0000 From: Frank Li Date: Tue, 12 Nov 2024 12:48:17 -0500 Subject: [PATCH v6 4/5] misc: pci_endpoint_test: Add doorbell test case Message-Id: <20241112-ep-msi-v6-4-45f9722e3c2a@nxp.com> References: <20241112-ep-msi-v6-0-45f9722e3c2a@nxp.com> In-Reply-To: <20241112-ep-msi-v6-0-45f9722e3c2a@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1731433711; l=5495; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=mRSIYGyE7Zx5MR9tyPF4Gn3e1jwej2qgCm7SNors/a4=; b=NXmYNgTDzlS+Hq5U4WYuoGLf8occAlD/CCAGqkAlLRZnc4PFuv+F0gpZsIxFueTf0Ine0Borv XHxiZ13h8IbBCLm7Gbh7I4eNcVMNIrnNU1tUOwb50LiMc3YOL787EOY X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR03CA0076.namprd03.prod.outlook.com (2603:10b6:a03:331::21) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AS8PR04MB9510:EE_ X-MS-Office365-Filtering-Correlation-Id: 4838bbc9-baf0-4f89-9493-08dd03424481 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?0Wd7eE/xIjFefrvFy6sBwDjWuGC1XLq?= =?utf-8?q?aSCn9H4pLu2d2qVlwHndDj59UOX5RWxm9O94VxJ0zUAMA7hzjWmLK9Py6mvgdo+R/?= =?utf-8?q?rlkKNq5scBSREmc/2KERP1o4frR6CK7pw4QIzbyTpiztLMoF/garmI1sSwNsXO2ZM?= =?utf-8?q?BK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EsA2I6xARNCxv81w8ARs2yR3JXlnUi12HF8eLmSfBb7p406C227OKo9y0VHk1?= =?utf-8?q?smmtpromeN4pmb/QwtZ9SAHKN+uR1RmBu8lwleoL6yPpjcXds7PmCz90Kfsz+7dMG?= =?utf-8?q?2YteSBJYr5C8pX/kkWwNR9ENn+p8UHMGkfbkf4z1xvm5PrN8bLfMRTBzFvYjVoVTG?= =?utf-8?q?CP1oqpudUJfX71BsQyDVM2tzRY0w2Yk/nTW4k3pAuB0NoM+v2FkK5Yzka/DiE89r2?= =?utf-8?q?dAW46x9onNAJN615rNkWGv5CruluDHIUSL+Boygb5L7zq6L/wwgJtcBk=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(52116014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?DOz7wVhAXml0EEWZIqEDH0l1n8FK?= =?utf-8?q?sgVcBC+Dxwesm+sW7rdeeJC67OTJYdtFnY3vfwyffCHUU2JC0t/zWfwgSDTL7tk4u?= =?utf-8?q?yE9BR0Ofg1++yc3lZJfFE5g5LClqqo74k/IeilmNQMQb0zhaO1At9x7i1fK88nmGO?= =?utf-8?q?jd8ARh7FroJKhpRbMdaSir5HyFYJPJBs5iw4hTvrWTD9idC2htt8UaVWZKG44xY9t?= =?utf-8?q?GsfrSOOXYjxvfujQ3HwzGnaviYRYaVVjapBMfgkDR83OBePgxqxKb30c8bnLobS2Z?= =?utf-8?q?KX52uYcjnZNKv4Xpl8gKDjYDpoc7hq6StkOu0Uqno8ggTSVl0nE3fdGyWUtcoDVZf?= =?utf-8?q?0/qCc3ToBiMBCrgDp5MSNW13IjVAdh2iuDkvGEXZ9k33UfEZi+LKaEJKIX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+nnBni?= =?utf-8?q?HWok9lEM+rV7fWfgU1qGj3hCUPL7LbaRszlS3FMpFcyJoloMDtiZtqeANCpBAMgml?= =?utf-8?q?FoCNKGSwpKarH32J9QIhGmN7KtkfR/Kgmc/lTaMuQ/pBVMGM5xQgg+S3qFbAbDacu?= =?utf-8?q?/lKzqoxs1hdTteUABMmFI7I424sUcqXWSkvuojGDPIdgPp/owOVMRZ9Za9dUpYl+B?= =?utf-8?q?37QHv4vnUO0hHiruwuzjbGQprcXG4YJ+6kKF/P3RpBjbVu/XrIGHo4t4=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4838bbc9-baf0-4f89-9493-08dd03424481 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2024 17:48:50.9661 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: naHTFPrVEySCb0JrFKpRrjcuwUJWUmg8Wsjrpu5dyRgokYdGwXJMQSm2Sm1ELBUWpCzJd8BK9j+hZcbrsv+3BQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB9510 Add three registers: PCIE_ENDPOINT_TEST_DB_BAR, PCIE_ENDPOINT_TEST_DB_ADDR, and PCIE_ENDPOINT_TEST_DB_DATA. Trigger the doorbell by writing data from PCI_ENDPOINT_TEST_DB_DATA to the address provided by PCI_ENDPOINT_TEST_DB_OFFSET and wait for endpoint feedback. Add two command to COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL to enable EP side's doorbell support and avoid compatible problem. Host side new driver Host side old driver EP: new driver S F EP: old driver F F S: If EP side support MSI, 'pcitest -B' return success. If EP side doesn't support MSI, the same to 'F'. F: 'pcitest -B' return failure, other case as usual. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- Change from v5 to v6 - %s/PCI_ENDPOINT_TEST_DB_ADDR/PCI_ENDPOINT_TEST_DB_OFFSET/g Change from v4 to v5 - remove unused varible - add irq_type at pci_endpoint_test_doorbell(); change from v3 to v4 - Add COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. - Remove new DID requirement. --- drivers/misc/pci_endpoint_test.c | 71 ++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/pcitest.h | 1 + 2 files changed, 72 insertions(+) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index 3aaaf47fa4ee2..dc766055aa594 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -42,6 +42,8 @@ #define COMMAND_READ BIT(3) #define COMMAND_WRITE BIT(4) #define COMMAND_COPY BIT(5) +#define COMMAND_ENABLE_DOORBELL BIT(6) +#define COMMAND_DISABLE_DOORBELL BIT(7) #define PCI_ENDPOINT_TEST_STATUS 0x8 #define STATUS_READ_SUCCESS BIT(0) @@ -53,6 +55,11 @@ #define STATUS_IRQ_RAISED BIT(6) #define STATUS_SRC_ADDR_INVALID BIT(7) #define STATUS_DST_ADDR_INVALID BIT(8) +#define STATUS_DOORBELL_SUCCESS BIT(9) +#define STATUS_DOORBELL_ENABLE_SUCCESS BIT(10) +#define STATUS_DOORBELL_ENABLE_FAIL BIT(11) +#define STATUS_DOORBELL_DISABLE_SUCCESS BIT(12) +#define STATUS_DOORBELL_DISABLE_FAIL BIT(13) #define PCI_ENDPOINT_TEST_LOWER_SRC_ADDR 0x0c #define PCI_ENDPOINT_TEST_UPPER_SRC_ADDR 0x10 @@ -67,6 +74,10 @@ #define PCI_ENDPOINT_TEST_IRQ_NUMBER 0x28 #define PCI_ENDPOINT_TEST_FLAGS 0x2c +#define PCI_ENDPOINT_TEST_DB_BAR 0x30 +#define PCI_ENDPOINT_TEST_DB_OFFSET 0x34 +#define PCI_ENDPOINT_TEST_DB_DATA 0x38 + #define FLAG_USE_DMA BIT(0) #define PCI_DEVICE_ID_TI_AM654 0xb00c @@ -108,6 +119,7 @@ enum pci_barno { BAR_3, BAR_4, BAR_5, + NO_BAR = -1, }; struct pci_endpoint_test { @@ -746,6 +758,62 @@ static bool pci_endpoint_test_set_irq(struct pci_endpoint_test *test, return false; } +static bool pci_endpoint_test_doorbell(struct pci_endpoint_test *test) +{ + struct pci_dev *pdev = test->pdev; + struct device *dev = &pdev->dev; + int irq_type = test->irq_type; + enum pci_barno bar; + u32 data, status; + u32 addr; + + if (irq_type < IRQ_TYPE_INTX || irq_type > IRQ_TYPE_MSIX) { + dev_err(dev, "Invalid IRQ type option\n"); + return false; + } + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, + COMMAND_ENABLE_DOORBELL); + + wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); + + status = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + if (status & STATUS_DOORBELL_ENABLE_FAIL) + return false; + + data = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_DATA); + addr = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_OFFSET); + bar = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_STATUS, 0); + + bar = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR); + + writel(data, test->bar[bar] + addr); + + wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); + + status = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, + COMMAND_DISABLE_DOORBELL); + + wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); + + status |= pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + + if ((status & STATUS_DOORBELL_SUCCESS) && + (status & STATUS_DOORBELL_DISABLE_SUCCESS)) + return true; + + return false; +} + static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -793,6 +861,9 @@ static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, case PCITEST_CLEAR_IRQ: ret = pci_endpoint_test_clear_irq(test); break; + case PCITEST_DOORBELL: + ret = pci_endpoint_test_doorbell(test); + break; } ret: diff --git a/include/uapi/linux/pcitest.h b/include/uapi/linux/pcitest.h index 94b46b043b536..06d9f548b510e 100644 --- a/include/uapi/linux/pcitest.h +++ b/include/uapi/linux/pcitest.h @@ -21,6 +21,7 @@ #define PCITEST_SET_IRQTYPE _IOW('P', 0x8, int) #define PCITEST_GET_IRQTYPE _IO('P', 0x9) #define PCITEST_CLEAR_IRQ _IO('P', 0x10) +#define PCITEST_DOORBELL _IO('P', 0x11) #define PCITEST_FLAGS_USE_DMA 0x00000001 From patchwork Tue Nov 12 17:48:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13872698 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2069.outbound.protection.outlook.com [40.107.21.69]) (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 63CF5217476; Tue, 12 Nov 2024 17:48:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731433740; cv=fail; b=WbUJ4+Z/HKmTXKmxoAZePjULPwTEGq0inZGvqTAuR93uWgCGfrFg45anE/XS+Er0gARzWkRgA+x9EVueRw4LmTWl6Nz87gaQGhplbFZifskEaSyZCc2EPlhVx+H1gelT+0WaT7RLe3vXqGW5knbvtv1K59GlsCKn0Gxqpsp9mDU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731433740; c=relaxed/simple; bh=rzBqaC20gv5zajeNqMjcGQwQsIkiSRC77uox8VWftBw=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=BNzy2toFU0F0IMH1cnprpSeIhJ7vHaPVGrHDsfTSZ4aHuYIUKmnnViNDIbU8ve8uL8OJHM4KDiIHbrV1A827JW9F+UbxOCCb4cZ5JIzRvC604i8wlWVQXRRXRUFmBpYkC9yFc6WKWwp7WINQM4CqOcrEwoTPz3gYLavSjPNF4Yo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=B+n51rI4; arc=fail smtp.client-ip=40.107.21.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="B+n51rI4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tDaJTbh7ig3+VMhGSjYy0AUCDQY9Gxb2HrmZ0UPd86shbs3KNg5/MVrVj5QIiKOSxyylrJQN0ZFnsogAIdk2IvhqyhpRdKOieaFPWLPoJN8XqfmHktb0Zw4hjPf7Yfpq7+nlVOXe+BFKgVWkFhi2iuy89tXSU96p8BF/nyOj5FrMEOUCMxmukYftt7W8gDYK5LyZNoA9YEAFLAZuPRmE6jJ5QUm6MhDnwKzkikIzVm8yoCWXpY1ZYQo3M8DQWMbn0At0ZMSHS9Ci4hxakVkGw2aa7+9ConcgNUT2F4RDEo8JkbRGRe45NdEZAOCn2aAF5IvBLWpQUsg4kOdnHrVXjQ== 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=kBY2RxtR8ubrdRv0IDfaOqn0Ih86F4aKaUUYok1m864=; b=UtBAsphfxsfgxHNQfVQSxPeGfUPRdye+Vb4e/EwP3gG3CsnNN09sUhFfU3vo9SirEpuu3Irdqv3+0lWcSIgfg4PvoersruE211ZrJOGm87Nmhw4/PbBSeReTvc23khGuzDzfmwn031xkeGT8svYZcKaWM9+WeKUxjI8tbKAAygAM/D9/e7oSh0DeNA4o5jGAOYAYKSmsV/wH7jVWaX25KccdWFtIfKqf51y6MjQ62yuw4sVpvrjHLIonB9Wir7EdTx92Eww/7Ar7pVJRxUv5tHRjMLJeyRcuWYo+23IMIhUgyYtixYc0mNDBgyJvWhTjTgneG1hF5hmUz0/sB9pE8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kBY2RxtR8ubrdRv0IDfaOqn0Ih86F4aKaUUYok1m864=; b=B+n51rI4FCqYkSq35UH4v/6UT/YT8agBmql3B9vIXAjKf+eoPIMqZR9TC0HAX8osZXujAyU1R5hHBFC9V8MKYv/Xvbf46k36BGMErZzdA44CB2gLCG4odBPuCMdC4nICv8NXTrltV4xuA4GIPj17v0vbFUd295o6fNa+B7H+V2ro4+n0Qe6AmqDvHYXDc5+nSTIL7nrlgMRYNiHHAcAnQjTn8shr3KsDLhwpo/g0boV+DJpAwHbvXWeeXtp7YHvAlgAmrH7G5FCn3IgNRS5RGh5VO1Q3PKKu12vdPZr7Q3etLc2BQupd9a4Nn1M0EbAaG+sOY0meWnW0fP1FaJMJhQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by AS8PR04MB9510.eurprd04.prod.outlook.com (2603:10a6:20b:44a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17; Tue, 12 Nov 2024 17:48:54 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8137.027; Tue, 12 Nov 2024 17:48:54 +0000 From: Frank Li Date: Tue, 12 Nov 2024 12:48:18 -0500 Subject: [PATCH v6 5/5] tools: PCI: Add 'B' option for test doorbell Message-Id: <20241112-ep-msi-v6-5-45f9722e3c2a@nxp.com> References: <20241112-ep-msi-v6-0-45f9722e3c2a@nxp.com> In-Reply-To: <20241112-ep-msi-v6-0-45f9722e3c2a@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1731433711; l=1850; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=rzBqaC20gv5zajeNqMjcGQwQsIkiSRC77uox8VWftBw=; b=5FmLkMranxnVo7GgjBazbOI4ML8SkJP0I+HYFwOFwUaNYE3Fy66ZH1fXI8Hq9cxnin7N46eBE hZZgOxH2tjhBVUHstusghXmo45HX7PbYV1p3KYRFwsCNQx97iOXMPkL X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR03CA0076.namprd03.prod.outlook.com (2603:10b6:a03:331::21) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AS8PR04MB9510:EE_ X-MS-Office365-Filtering-Correlation-Id: 617b773c-ec7c-461d-8b18-08dd034246c0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?NRI6sgg7HZ3rNznoE0raLqdaNScA8Nx?= =?utf-8?q?nwbg+3N0BUO/9zdDZ2Y8ELbIZnJuziQyB82lsTvDi2gwH5lriD9EwLYC1q+A/QD5y?= =?utf-8?q?D+fh0WcxvEPeVH5n/pYYGTBe0nqVVHh4tE0D5DLEf82hwpZPArZulxNK0VUzC4zDl?= =?utf-8?q?pVjmJQxssHl0ujVY9lVP9y+tIxE6HifJYgqhCMnwQN/tqDvlolpPUilUfoGrUOmG7?= =?utf-8?q?DDqrClW44lNQ6OvuIbgaWKFUKXfv1d1TlqLpC6KUyqm00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0Wok?= =?utf-8?q?IWP3QwpjHxa3p9XMhLQCX0bEJQ2WcqPxw26ESs167TGCXURBGTPdfy4hWbxaCbqTk?= =?utf-8?q?HMewh6i94GEo06la1HnVWs6AwClfM80E3EnCzZA88MeuXz2TrWO9MA/xIuQwKyOT2?= =?utf-8?q?JwKJ0494X0DJtfolglFeJoWV121mKzaCD0p68U4EdSH9UM+toazeTCBA=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(52116014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?0RfIRLTklnFPyjw64dEu++jRbFMu?= =?utf-8?q?Pic4tNNnqsZZF4BqPii9nYK6YysSXHs5qCQBBryl1ObXfJefb8kNkoE0E1kNBYijA?= =?utf-8?q?Iau/V5SPdUm7lpqID/xCJG8nHXpNE2JqDYtHJQMUQ/LnJ9JjpAwOk9MCXZ2DSU0Ia?= =?utf-8?q?CdtU+MDfiNgJqQlFAQCWq+kdxJX5azbogCPzttQQJrb8k4cw+I7uOqu+MK6VJ5Pup?= =?utf-8?q?UkHliPbkRBFxdVt449UdcH4Cv77v4OAwTj1UQf1mUtdeoupVc2mb9d6o3dEtIGlG/?= =?utf-8?q?USAx4jOPcosvW3Nd8Q/jBEBSxeCftMWd6AIhzap+JrnTL+bCtd+itJ6+UsVjkqjLU?= =?utf-8?q?bilrpQFsNHdyqFXGC7zfE0Nli9gMZZwvYp3j+f66+wmWmkGfNTdphodNI52ynVAcH?= =?utf-8?q?v7Tp31A6DKG4zjAYwWRZB3NyboGtjUPY5bOjuZJTSe1rJel1DhzVY1irOtQjxM1RL?= =?utf-8?q?SX1YOC09zBX4ugqXfCDNQV9oxn0+6rrSHNXSz3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Sn24wJyntGiignLG4L1VE3?= =?utf-8?q?e5PVOjMIpSspg6zkUKD987um8b7s07tgIw+2uf2T6z2WjsZFnNLAGvL9jVqjOJ9gk?= =?utf-8?q?ex5+bkPTT1FwsMeMPAVGWf2VXbmHgh/HXEbM6GmX3Bw1aFij+2LxoqYc=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 617b773c-ec7c-461d-8b18-08dd034246c0 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2024 17:48:54.7259 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: k0AOf9R8RwFvzpKJ/zK0Ej/MA9jIrmsjA+HfUQfUf/x2rpVocFgS9MI9RscyAmokBTAaNl7sLKBU5sdTg/iwuQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB9510 Add doorbell test support. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- Change from v3 to v6 - none --- tools/pci/pcitest.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/pci/pcitest.c b/tools/pci/pcitest.c index 470258009ddc2..bbe26ebbfd945 100644 --- a/tools/pci/pcitest.c +++ b/tools/pci/pcitest.c @@ -34,6 +34,7 @@ struct pci_test { bool copy; unsigned long size; bool use_dma; + bool doorbell; }; static int run_test(struct pci_test *test) @@ -147,6 +148,15 @@ static int run_test(struct pci_test *test) fprintf(stdout, "%s\n", result[ret]); } + if (test->doorbell) { + ret = ioctl(fd, PCITEST_DOORBELL, 0); + fprintf(stdout, "Ringing doorbell on the EP\t\t"); + if (ret < 0) + fprintf(stdout, "TEST FAILED\n"); + else + fprintf(stdout, "%s\n", result[ret]); + } + fflush(stdout); close(fd); return (ret < 0) ? ret : 1 - ret; /* return 0 if test succeeded */ @@ -172,7 +182,7 @@ int main(int argc, char **argv) /* set default endpoint device */ test->device = "/dev/pci-endpoint-test.0"; - while ((c = getopt(argc, argv, "D:b:m:x:i:deIlhrwcs:")) != EOF) + while ((c = getopt(argc, argv, "D:b:m:x:i:BdeIlhrwcs:")) != EOF) switch (c) { case 'D': test->device = optarg; @@ -222,6 +232,9 @@ int main(int argc, char **argv) case 'd': test->use_dma = true; continue; + case 'B': + test->doorbell = true; + continue; case 'h': default: usage: @@ -241,6 +254,7 @@ int main(int argc, char **argv) "\t-w Write buffer test\n" "\t-c Copy buffer test\n" "\t-s Size of buffer {default: 100KB}\n" + "\t-B Doorbell test\n" "\t-h Print this help message\n", argv[0]); return -EINVAL;