From patchwork Fri Nov 8 19:43:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13868865 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2054.outbound.protection.outlook.com [40.107.22.54]) (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 E5D021C1F16; Fri, 8 Nov 2024 19:43:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731095035; cv=fail; b=Tqdb2RloVDKq+JrcDrUGqCecT//PTFafImNsblCirnNJkyQzjuLhjJQ5+QTojRbySkjVq4QVMTmzC690fZ+vRLyGV9bplgFT9jGM0aycvcAuhvnGXH2PvMTnB4mbV9GplsyxSVwH5hZ/63MabkicSh9kw+NhmnaT76OCJaXMI38= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731095035; c=relaxed/simple; bh=WztdJXCK+bOn8jeGvfQAh0AF4COBEh+c0a1xNE6MdUc=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=YjOlbrKIErVL5gv0nhz2ucdwqfTgV7XK+rzazBL3dCp0vWNy+zy4r+zYutD/N5f4ePF9BKmoQkMPxbSG7BwqqV5Iq7RqBT0L01sFKyHoWKQvMiTbAKLswr39thKt+EMozwRppF9bHnRM73kYSIpnSupxFc8og9ReBm7YGFmDYY0= 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=j5J5RoFi; arc=fail smtp.client-ip=40.107.22.54 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="j5J5RoFi" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=N1lQs/34QqmHGoYvbZK/tIVd63FRX4AP5vZAaUNgaWu4jRcVdzWmYQCJPgQnULvJzve5dNdxGiFF2zqMeFw8tPigftbmrIDYEZ2VyoJsd4A14M0XbgDzzwxoqNrMsYkND7mwPiNqw5CDC0PGlBXAS9Ss8fEMf1Nz4ad01kQQPcMXEr4xV/4Y2o7aDjemWu6lmz8jz4BTG6SYRHwbSQm4qN71YActgMpAAbzZPz1mvKOzpsuceD+u3U7zgRs4b0MyL0R+qSJqV5puXH3Xeam5XhLBrpkbm55yFuj5UvKhrVSPPaaKro2sQDdOjSTtxrhDoRuLCzq6ZP/bjTEHl18cZg== 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=Oan0nT460bnBSfdOKCXlsarwBLEOZ6HSByQIFZo5Sn4=; b=gVNoHuklKIZ8upS71l/vXyZR69j4OCFQrDnlTE3Do8BvkF3sLFj7gnpdI/UPwJKRDWiXzdHGr3JC3dlcX9bbkJfvVW8w/eQC8lopZCJe3SNMGdfzHUFRTy0kFT4ZzECkXqgiMXwiVebjrdB64inncbkpY6UezbTyrYVkcT8Qt9xbFw3vIkNUkAYpOuMqxlpZhxJjP/1YWzLkpyQPppa+miPe39dFzZzMXKAqaI1//cnsf+shtLh+Hd+8eBTxpI4AmK8v/YTGa/lZi0FGTtKCwauaOmor0hRzGF01NX7cr23SGCBfwGkVSzk1UG1m/ZO3eF+LdYhR1ggD41zMGqwOog== 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=Oan0nT460bnBSfdOKCXlsarwBLEOZ6HSByQIFZo5Sn4=; b=j5J5RoFi/khEthsDtWlfpefI210zhUETGEerKIh55cavdS9OkZL8zIxr6rLsWm0ySpItPStK4u9MOWhypmhwLLTBVsHMqDTkpJl9dd1AZlp/LA+oQvlnNyI5F9iPSgAk77VJqDz6Rj9YlqKwaERpZx7WAxxfdsGtmpFnAr0pdg4kRta27U+RYEj7yjA0t30ix/cl/PucVR4VlGYrnkK1gDbK51WY0wBn4Ury9h3IPoyzVl2meSHLA4B59LSG4gpSBG0FCI7YQnbPos9azNKARKJMq3nhA5aCVmBTpDE2LtItNQPXEz9Vba8U32pGrUj62EwRWNUVqch6HKwdmEUhoA== 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 PAXPR04MB8669.eurprd04.prod.outlook.com (2603:10a6:102:21c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.21; Fri, 8 Nov 2024 19:43:49 +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.021; Fri, 8 Nov 2024 19:43:49 +0000 From: Frank Li Date: Fri, 08 Nov 2024 14:43:28 -0500 Subject: [PATCH v5 1/5] PCI: endpoint: Add pci_epc_get_fn() API for customizable filtering Message-Id: <20241108-ep-msi-v5-1-a14951c0d007@nxp.com> References: <20241108-ep-msi-v5-0-a14951c0d007@nxp.com> In-Reply-To: <20241108-ep-msi-v5-0-a14951c0d007@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=1731095022; l=3101; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=WztdJXCK+bOn8jeGvfQAh0AF4COBEh+c0a1xNE6MdUc=; b=WzIrwA/pzq6FFZORMOHmhUyIAxZ/vFNUiz53+QK8oEmX6EA51zP1387OhPP6QBwimkhPeoaJT zFiTsNr8URlDDwYKP1gZMlrVSwKWIcfVnPlwpU1HMmAtL0rHmmF3Uzm X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY1P220CA0026.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:5c3::17) 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_|PAXPR04MB8669:EE_ X-MS-Office365-Filtering-Correlation-Id: 1e3dea47-3e97-4c6c-65a0-08dd002daaba X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|52116014|7416014|38350700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c93TAeEHXmWeMC78tiebhW2WeXXCETgLq1AJltocjYhvuNqORHgREvrKBhWn?= =?utf-8?q?XDB3ZzNJaUgss6Vtq6E/w80qI7YUf8acyVnVJvt/NPWiBSJpaF2fozlVxqVdOJ7iP?= =?utf-8?q?U/sDlqNmXjf/49Ub2V9PQSErRLuq3sCCvda51TYFk4VZHZZHJ1j+weqea2VWMrOZi?= =?utf-8?q?d4suL7Ma/pnTdbfA2JM3WdtgbnMZuXWm4gRhd8cK22CwGapLS5LS4ObxhaA0R6VOZ?= =?utf-8?q?V0JGhDzpGjw/XlPZ9wfAA8U2DFuJB+nVmDoBD7Ns4vZzjIGuI3JwHPBL0/EyAayW1?= =?utf-8?q?CjQ+OFXzDoSW9BSXSiCkzS988DzqBSR/XQMBihOocGtFkpUr/TdzxD4OFHSoetxWj?= =?utf-8?q?l9jPWAKM6p8ecbcnGHXFte7q6C3vWTLW/j5af0Tnu+wd8ALaHoxspskMkbLivA7lJ?= =?utf-8?q?O1btlvK7PepdMMjf3IQppvV0z+yIMorYpEeZ5uIj3Ip7r/NmX2RGC6VU=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)(366016)(376014)(52116014)(7416014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?vValyPjlEw5VCDveuShf1ozHPzYJ?= =?utf-8?q?Ip/LkSeibSQ0livpekZsrQW8f+WXcZgqaapYE8+b3YCVg4MQf1QyEm2xkB66RNPH0?= =?utf-8?q?CvwBJzMfJRjko32ZGTjkr+qnrCC7iB0kHPrD4gI90IMqcWLKCaTnDQIhnvlIQ7bQU?= =?utf-8?q?/nSsr2F33iM4Srdj7ikxuNvno08DMMZn8+qEdd8i0a3UeKZQFsi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RJtE3I2RIuwb?= =?utf-8?q?tomDyhepJVnIAdZnIaH+UgT/pidBnku5MjsEe58h+6hCuu3tH7mgS0OkDSJeNLHwR?= =?utf-8?q?jO2YY+XcpqImEneWcyBHkIxUUlBtNsnOxium9KoFtv9mbSuqfSdcHObd4dr/df4GA?= =?utf-8?q?CzlSdk6FZw8+WPivj4HrYxbTGCqk0nnd6SxJcJIqEbh5RysFB7BxiELddNnnr1wYl?= =?utf-8?q?ybzMVjTQi71pEMXeyOWtWR0094uusixRsKtwkHYDQDh5E81avsNgB+5IoSuDWsXsj?= =?utf-8?q?ER6Gq3zMwvkhOk7ZQgO7Aqw/JpNegJCewjMnNeRTiFuOHaLFUCESoDw0NhK5F81Hd?= =?utf-8?q?GJALjhr8zJPKAwQbd8eOrwumKdyjML90zzmp2rMNXzzdZJJ0gPocrhQk+xiJXrJ/I?= =?utf-8?q?AI89asRAK9CDLtWYJFaGv7e9HqpJxZssJLDh0sscN51jBI7g5E+zlfY8pEW2GfvXv?= =?utf-8?q?fD/cCn9O6dsP?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1e3dea47-3e97-4c6c-65a0-08dd002daaba X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2024 19:43:49.5333 (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: 0BTpAVaYxm2sEosB8PeI2Lv7NtDyfSrRv//Ftm+Mioc/l5ovr/3akshbjmpk8OMiacRwf7/MGL+Kw2Xmv2TykQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8669 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. Signed-off-by: Frank Li --- change from v3 to v4 - 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 17f0071092550..14e6011df4b2c 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 42ef06136bd1a..682808f4510be 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -266,7 +266,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 Fri Nov 8 19:43:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13868866 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2054.outbound.protection.outlook.com [40.107.22.54]) (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 668A71C1F24; Fri, 8 Nov 2024 19:43:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731095037; cv=fail; b=mOugpms6ASrlrIBBCRhomZSxdSqX9RSyNT7tV2PeFTKEN3hlura91dapuwHRFiT/9EMvLqN+E4Z7t3fILiJK4njDASotnDnKEVh+wmuG3PlLfhspwC6OMC1EOH7sBXzsOyqcFUtly8Ysz/6DXO8cX6pmsbqq2yAf6a2tPQfokfk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731095037; c=relaxed/simple; bh=qYxIU8kchQtHsEa3c+NUqckv3V8JSjV+g2iyHqr0Y9w=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=FOY8zNN6QtuoIru+xv9CH54DgPbtbddYtOMA0IF4/8GCJZ/KgxHME1y1Vyf+Qcg/BBttAOFBHYbFn/Y+rkI1COsfz3HlZHblN6ytnULKUwD9vU9xwvgyorO7iywoxGU8Q2qRKzRK90s/0vR6LFiPPXOq05pesDniBQOd9RxJsTk= 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=kC1LrNR+; arc=fail smtp.client-ip=40.107.22.54 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="kC1LrNR+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mjr2r76tOPXDIddMzEF/ZZjkKPq8qXgguWSB0vW6Lh/BhySWa6uEAFuIUMXKnNCA/lqNyv0c28N+tyjy/AQpkge3LlEkOGn5iNLq0eTB1wH+yAZE+69/mSI4pNMsWipvnUZEUPUBGDbpbfB9MQIscG+pMh0MqNMAi8SvuWSphJa5OLG5jW4wTvBwYNVXHs57xmEDOxh/Tmo/8O655oLXQ/cvaI0HsABUL3D4ysZyxh8tckRddFetsVhXKUCejzrOEeo9eGK98EXX5ss7JKRZmysyylpoAyMfbXj7WW1+DlaICUAEnGtmaD4FTtF7XXt02wMce15n/rN6PjBTKna2wA== 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=z2SKH2oS8EKt3hJu2TO5lwqproQ90A1PIbYf5vAd3Yw=; b=k3dHLY3j2mSpX9NDrpE9a/mQpfftGPG6LmcT4Mht1F2SBSVbctISWVB3OqRRSCQPG129RR9IOGbsov7vyjFMJsuSagctw/ixQAKgbs0MQ/rQbwAPjBHRVtw1HSPAEqnWs2dRPg85kgBrb3thG11EqFUqqRwbAVpPdEDZeE+J7DfsCvjLcUJO7Jy3ZKIwqvYKwssSRmj2HZ8s6cxsh1wQHWLwNLQtHA2Rps6XKhbrmqu6ul6IpP7ygsOHX84cbhb+LEl+16RG8n/+NgZ4Gzs7Wkr66wL9YC995jZUbHUqHqvFhWIa/u7uJyb7YJWsXXFIh2IruCknNk4OrwTFMLEJcw== 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=z2SKH2oS8EKt3hJu2TO5lwqproQ90A1PIbYf5vAd3Yw=; b=kC1LrNR+9kV5edRjY+UVsZwJLJT0Ad04ZwcvlQT/Vx0eScrtx1C32l7THJ4o3Y1u0EsHKFzyar3oHvw4grWXyajeZqPaetosQaBEhxx/+ic6yv4hzEKzlmSaq9zneud70wis+TnQROyLA/jbJMiMX1+w2G+DYr9eCPAUzDQ8Yp6oxCF8sqS4GfU6chdXgru1/LWFcqSO+fexBmafrr1+MmTg1M5j9wMMJ0t0LpaDhFIBErpEP/8/0XQaCRS7Z51d6gpPbzvthFaWuBumgBZkHCQ04yPBybyUtUK+VzXoMrJVh4llutHelkThQ7CE07uju2zgtKy0ZSCGrkBzTxxKQw== 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 PAXPR04MB8669.eurprd04.prod.outlook.com (2603:10a6:102:21c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.21; Fri, 8 Nov 2024 19:43:53 +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.021; Fri, 8 Nov 2024 19:43:53 +0000 From: Frank Li Date: Fri, 08 Nov 2024 14:43:29 -0500 Subject: [PATCH v5 2/5] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Message-Id: <20241108-ep-msi-v5-2-a14951c0d007@nxp.com> References: <20241108-ep-msi-v5-0-a14951c0d007@nxp.com> In-Reply-To: <20241108-ep-msi-v5-0-a14951c0d007@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=1731095022; l=6220; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=qYxIU8kchQtHsEa3c+NUqckv3V8JSjV+g2iyHqr0Y9w=; b=B/e51zaazNqgVAEv7Uyg42iGV3dN+UwtuAT8I2kJeQRw9NZeabJN8dxxMdVuIuXuIBRPUXf/P HfiMe08bSL4BwAIX7a/Bpxd5Raq3wx4zWssS8I2eswr0sNijtWc2tF1 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY1P220CA0026.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:5c3::17) 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_|PAXPR04MB8669:EE_ X-MS-Office365-Filtering-Correlation-Id: 61523f2f-c7e5-4bc6-23f1-08dd002dacfe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|52116014|7416014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Z+DJ6CashoiUjH6pudVgrUYRFf3uuAw?= =?utf-8?q?keNWTnm7nOjIvmzCEdgqvNgdiNCrUlAtlnsXxOwhr7Ksg+01DYeZ4fz7WwA2c5nig?= =?utf-8?q?S3MyFN/VDdNtHlRLvlOe43gVPdYY0NP32mNQw9/jElLkFUxbkcNzXvqHeHTuQKdPN?= =?utf-8?q?DygAHcWC71kr0vjL4B5+e09HuWq89YHd586lXz2G5xlLhtv1MFI+MIYt6Di7TsJmn?= =?utf-8?q?OUhrEVHJkKn8bZr7fZXS67joTDEfiG6rB+Iqzy6n/VAnkvNBxv0203dehh7rNb0lh?= =?utf-8?q?GrbVR4NsYLVBdD7WZj/GYPrc5NVQoD0175uPSYNTdVVVnqfnHZflitJGQuGe3YXLj?= =?utf-8?q?d7dOnht3DVJCmiSeHT3wZ7Zhp9B4sTnjciZo7fG4zAcBArXafq3Y00a4d4atzc0ha?= =?utf-8?q?AvJuixMmhU8U1KetuZpPIlmlaWEx8LYu2cCQ3bkT8YnZKp/iBj8x51q7zMhW+dBwd?= =?utf-8?q?U38PMeXUy9aVzji3b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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)(366016)(376014)(52116014)(7416014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?A4aqoM0heLO+5JUwqbq3cYB4H1lq?= =?utf-8?q?4Z+jmrTxMawi3TX5tgtC5y9htjIAjrXWBPgJrib6griji2t2tvhpZg2MvNGlZZ4ie?= =?utf-8?q?ZC3tWM84Dr+cYqfSuKpz8Tbg3jL8Q1qgbe+YbRT92Bk3MNbJbBUHBakbv5w0vqP5I?= =?utf-8?q?fx3fgBXNZ5qRE22cwCL5r6d6fCvPUt/pGRoCCwu+t36nMfoEeifQH9xmUIc8iadSj?= =?utf-8?q?wBgrvNQfNRtKCZqCwA+2mIf7xo/K96vzY1M/YURsy1KDNfgJqWTa+PJBczxtUfvWE?= =?utf-8?q?vbfN+45YEnpaTZ6G18Pw1G/15SrAErNqWrNUFq974RQg5deCKqreTT6kNcc6rWUkP?= =?utf-8?q?VEJBtqnUWcALHIY2//J6S0oYf6b+3D0mNs4yTQ0Oe7pszb5RRJACs6PyOjabY/ED/?= =?utf-8?q?aV0kEu03KMLFgyFYiuQdDRkgkrONlIFd87nMoahhtZKZgmyhoYbq2Ra578hHuXR7s?= =?utf-8?q?f0K3SQjsV2HgHwbrZSBrcZmKvDrdfY/+/G29Zu2k491s6Pgo/cED36HlKrD89hQoE?= =?utf-8?q?zmbb+HzwJZ8EtVdrfxP05PZb9N5UJk+I+HISCGwr91xqMU1ageMJxp+99bbyGwB5d?= =?utf-8?q?X7UlkONtolK7ZZNWqPblTtquN8v0mOxU6m0VkbI4gR+QhnyonP0FKfft29aCvleyH?= =?utf-8?q?MVKddwGieJXxvTk9x+mLHlefOIG7eHfoji5MPMY+TEwsDzN+3kZGg5d2ovfdK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Id: 61523f2f-c7e5-4bc6-23f1-08dd002dacfe X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2024 19:43:53.3086 (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: aCWTffUS4Lbs1e4uyU1obX18Ar5BLYOvbF4VPNqae6/nkseXbNsrASowY3chT4orWb3KdheJeLnUcJ5VeRfXzw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8669 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. Signed-off-by: Frank Li --- 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 Fri Nov 8 19:43:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13868867 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 7E62C1EBFEC; Fri, 8 Nov 2024 19:43:59 +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=1731095042; cv=fail; b=FG2mKXIz+hpwhm5NGoVZ1hsSpiFfiMvvktOh/snQbV0FvG0Ravd1kCyc6Rphx9OIvgxTEtT4HzN1yQtjwdk5qSXBpLGMg9BHLKwMxQH6Z2C5E3VRxs9H8iMpZF9jmP4kxEnDonOgI5G0PE7y/f2HqPcv1SHDtMSNyu/fB5GMjGQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731095042; c=relaxed/simple; bh=pYt5jLNYZmjwZJXEi4DDlIg0upH0rCO+gYIhEutBvCg=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=PutdOO5Ko90RfQVGfbwlv9NtyHQgVoLy4Y3qH04viHx2HbgQhIl9nkug5dVxdr+8YHM+u7vjN1jhpNjnWaH95n1J5B9g7AiueuHMrBp9FosL0+WSTsj5SK1+I3hsPTLrS+U4uwYQnH7jUiYisvaxRlNv6nIdF3hV41SdfuL/wM4= 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=KWvZfuxN; 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="KWvZfuxN" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KjYqbyYOQxP8U1vnHqaNvIsEgPGq19dNe/UBHmAL4otL8VPtMvQ5LI3p8bMpIo1yn5M34yRvcxEd/mGeNOek0BmVAClK960hnTHbHv9hwDRBzKYJtcnnohCER8wf1/A/uhqCVu/S5HNBRbRucI2cf9RlJCpUBL4x2GkQXKvYq2UGFZpUaF6MCiuY7mrmNwTq1xpQlE4iprDda43n8UESuXf7Id8c6MxIgwwdxjP2C7RdW0Uze3BKrIlEyLNdvzy4PSLiE9d/PPTlRxCzZQKGJPnVQOwAqdBA3BSnZiGDrDKBihOlKc0fcVcVLQpfmwAyS0QGAGAcrG5R1iLad5OKNw== 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=HDKjFU4cXoZFEgIfqxFbVQhZAT91I1Dpe/rORgznK00=; b=TT6FBwKQL4CZwiKImXAClFADjqiC9AcZkk3DOqIA5Z+nVTsgqGFibpvSv9kfJmfDpblcWCcRqAFGcJflbf22GpmhSdEu4HZ9HWq/LRmfbHRA6xh7O4xcRFJHyGgddBbdhaHIczg0gkr92dhyHla+JNRA7vX8O2IqWSNkhw36vabSX+QtRKBWdKRY31kU8n//Yl/5FHPrM0ehDHzjV1DtO/u01krg1WHJrv7H4l4ry5/0XdBASH8q1ylW2iko3MkuL/BaycoO7X0mgpgLZNta89957AyQRhKWfCTvNxvn1ogOstBBjEZ0u5u0fORvzAnid7ioIItP1+9zU7WlpEFL6Q== 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=HDKjFU4cXoZFEgIfqxFbVQhZAT91I1Dpe/rORgznK00=; b=KWvZfuxNQ/eIBUnqYVS8crOC1r0R/KQpk+59Y+xCwSspAoYBd9xI/bVMk5/THbEhpR/DeRHnkrAnIadcSJ+fCtzHm/y1mGRUKOihWZcGmo14sc58uBfgBa7jxLD+dg+QoP3/McBPPKXsZj117jL8RM30jR98mSy5z+MnlC97ZT6cKo/YDKsjaqkKz0vPZ3yJMVnbPPi6QHtgW1bfMYzgl3jgcBQB176BWWhBU4miuUOQiExCLC1M/OmdGU3rFX7QZ/OlbTX2t96ZY+ZBOXLVEFrLAy/Zo3s9THzDS89lAtdkrlybIMmKs67XiQnCOieQkr1+U7LQvMA1hfvZng34tg== 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 PAXPR04MB8669.eurprd04.prod.outlook.com (2603:10a6:102:21c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.21; Fri, 8 Nov 2024 19:43:57 +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.021; Fri, 8 Nov 2024 19:43:57 +0000 From: Frank Li Date: Fri, 08 Nov 2024 14:43:30 -0500 Subject: [PATCH v5 3/5] PCI: endpoint: pci-epf-test: Add doorbell test support Message-Id: <20241108-ep-msi-v5-3-a14951c0d007@nxp.com> References: <20241108-ep-msi-v5-0-a14951c0d007@nxp.com> In-Reply-To: <20241108-ep-msi-v5-0-a14951c0d007@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=1731095022; l=7940; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=pYt5jLNYZmjwZJXEi4DDlIg0upH0rCO+gYIhEutBvCg=; b=+Oon8qydEw9hdV8US6oyNRAUhHdoe/xxsI0lkNdnDSUxaqIUS0awY3qKYNCFnWbbq9X7xDxfd 0ybJMRHNRd7DxpYoEMsSEbgwq4iwrj8WN24HlDKZCRAkFnKXEqMPBeU X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY1P220CA0026.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:5c3::17) 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_|PAXPR04MB8669:EE_ X-MS-Office365-Filtering-Correlation-Id: 3abdebfc-6d88-4adf-764a-08dd002daf3d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|52116014|7416014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Fb/BfwH1a6K4YpJzQmu7ZgCvnFEOFmw?= =?utf-8?q?/DYv/Nwd6CqN9CyjeLCLzp2BAjzu+5F1I9vEGhTZyk/264+/D8g1cHg3t0UZuHlVG?= =?utf-8?q?PTFsU4udO66+J3GbjH7iZxC6Qw86vcYiyw24mqEzqjL8h0XKT3LLp4HdCpdMS+A8O?= =?utf-8?q?RNB1FDGD/sWXW4C5KzqUSSDuKTFDJXb1655GuIsvilmo9ReocGbkXnK240J/zoZiK?= =?utf-8?q?y+OqZSEUrwa9BNMlzPa2Ev07alhueOKWnOiG/t4ifJrLP2ynXmkZGgrsgUCkdSm9S?= =?utf-8?q?J+JrjdKOYM55Cm9gjSHGEkPhPKIw29r+NwipS4Amaa6xtbfC3C+5+0pQgu1nVQJlB?= =?utf-8?q?OjFWkhCG8qXejLFnKeF3ZoqGTNR/81szBECNLwUp7tmVfCVk79R0xh4EWsT47jErn?= =?utf-8?q?LZqO04YbIe3kT+29yKeMI5vyUyzSeg7KyxB4U3sjV3WNZeHhG5bBTafPjmCPsb/zO?= =?utf-8?q?PT/8GWXGEipznPRkOIpttiRfEJTfMYtXhRh9lkgs23iVjFqU45k1SD5XsXMyN1K4y?= =?utf-8?q?MpeRKTRCVaSmXp0MIUb51vMB5wLQl1cqrOuBmC39wRW5oiKD+GiaAJnPyROhZ+z+C?= =?utf-8?q?ZoTsz0VxcVMeHJ3TmTC7rwZGg31suiZi3robIbw6WMk1iylKRVLLJCawTKS0Z60Sj?= =?utf-8?q?Ecmp1WWCCbG/zzDmpBTeTKMkWR3qDuJz0RQQROmJ2ZXEmzcT6B+pF5OSWEWIZlP9j?= =?utf-8?q?5t6vNjCdCqgREzijbghaPUumAyLUVBBa4lPDgax/XvFAAwb96A5pFJaBZuDDhLQSq?= =?utf-8?q?nsEO1dTokM+iImbPvUYIZuqBjCxC0tMCYXKLpDF4wZmxcJhrZ1uqy1zQbVQJcOfHE?= =?utf-8?q?DrYoD51TgOfd8uCUBTDvs4PcHxO0BEGYpw24QrXDb+el8AKn623ItDrZ86Gfgea8b?= =?utf-8?q?PspE13vWYeOXeKFlkij0c3IbyR3YqkwQ3WHHwrQhEXs7bSccieNZASJMPSZoh4vUU?= =?utf-8?q?JfoLxv41XFNSpFlpT/Eo9CalbAn/JGJmOSvRVYVUxZqUFs9xypGhZ1bPKdrzn48xS?= =?utf-8?q?G5q2di6sXJL7mHfh2H4eLK+4n12xlIhT10/JNJ14u5wtdIfxjeQGIsTJkPtiA9wR1?= =?utf-8?q?TTimhg/+kkZ30Kjwn0A1e8lhQiGox0+sijAX5bT9nWNKqzEXqCBzKTG2XL/M+3RWu?= =?utf-8?q?E01pUppTFQld9OR82w4qNcNJNHmZC6Oyg1wAfwd3m353ynIbAYpIhtx7j9utQpWjF?= =?utf-8?q?TAcV3ZQdTXejqSrtOyUoxLYV3hGn9LjlfokwsTgdj8MQ94hRimKOUxUXLza6f3Uis?= =?utf-8?q?U/+uIcV6YEoOF05IHRbPogKiFy5RekzOKn1271oylF8R7xpBBhW2VhYo=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)(366016)(376014)(52116014)(7416014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?cBN/L/PYoCIWZ/P6VP+/tsWVWKgN?= =?utf-8?q?MB9a4CAO+jDDChWJL3iXk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ay895ZHzqXWYRUVLeij6sNtRR2Um1ndY9Iz9iHPU1FEOReW?= =?utf-8?q?jxpt6owoGB3dd9W34E5tc9vN01fOczCydWIdPe+37CBwy+6WnZMLW+gGmuzcujvh4?= =?utf-8?q?2o2Ivk+ph/TSxmkOY9M78w5xPNWzlUhdk6aafZtTJA7hL4TSQi1nGVPrQnLcTy3W8?= =?utf-8?q?JdYHENBeJyvZL4D1bcRW/JN2EK6HvmhURL0fxUb0oiJMt0DdLEqFxW2LbGbfSlmVu?= =?utf-8?q?GeQ0uJqOvQXkJncBbW8C361cwg314pmuseyTPFAp3qJFzqG/WGO29dNaTkuyfn6ex?= =?utf-8?q?nJSnEnz7xvcFRzMmf7x0rcjv5FYFQIT6n5gi4v6MljyHiMnWhfA/4fHD9/fk2smy6?= =?utf-8?q?jbPEBzsW70RvDTyN9ndGzW1mqa8wyzhjM8qSup+S2gSjGBDfus8IWQAsIh/26Hud7?= =?utf-8?q?AwCsWnFCV2cY392T8Oie1CU3LK7Rtyese/SZk1LTWlRCea+KAdC6bZ4oCdLQb7bP9?= =?utf-8?q?tSH6htOCbSbu3rLttXS/k4Ha95Zm21Un5QODAMZXkdeTHgGYPjixty+K2tyeTVJbw?= =?utf-8?q?qcSlOyDhiXnqm+Es2kRuE+3dDXOpkHvOQ4RWU7arwSgpj5LuA+UlOiemBF+dp4CRY?= =?utf-8?q?6wW6+NaQEdC+?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3abdebfc-6d88-4adf-764a-08dd002daf3d X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2024 19:43:57.0759 (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: x3yULh7EzlssD2/epa1bIeceDlBqeRRs5umjC4szxJqa3XAUh8bmP87i9d5bQ5H+6cVbxNiK8aJKIabVqxAXRA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8669 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. Signed-off-by: Frank Li --- 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 7c2ed6eae53ad..52e36c7c04c85 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_addr; + u32 doorbell_data; } __packed; static struct pci_epf_header test_header = { @@ -630,6 +642,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; @@ -676,6 +745,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; @@ -810,6 +887,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, @@ -909,12 +998,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_addr = 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(&epf_test->cmd_handler); @@ -922,6 +1045,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 Fri Nov 8 19:43:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13868868 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 0BD491F26CA; Fri, 8 Nov 2024 19:44:03 +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=1731095045; cv=fail; b=kpuQa1HXvJWhTdnK0lJqsCgpWextnQUXaMdxJhEGCXfvZCu0ghXwevUH1aWN7JmBErjDwpM84W2t99bVim3+4x7i54P9p7PmEImBDbCfH24timYRzFzlz2X9YSzG2Eoyuf3CukHOhA9PTJwa+c4t+mMgBIn+PQ3dCFMtlnWZ5mc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731095045; c=relaxed/simple; bh=SU3fKgx2Cixu2vdRhLxkwq1ELVV5yh+eHERg3ui/hfM=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=V0JxH/dPOIz+Qip6riAe+WHH83GwphIf80RE2Yfpf+sdZBHgpEJ0ZMPvk+uRwU1zxAiWzqouaMjaKmMS4BhTHlyLcOsUmKULjqcYd7lP3TQ1M2WRaOENdHb8+XicQG0uGv2Jsnij0p9SH7yl/pbSIkN1Amr0mAzWKyoavNi1sXo= 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=apToalrw; 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="apToalrw" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=A/BWNrGVJoReaEl6npD3/C9rzhck6Ddj4E3y80cN1wIIFFdDygyoGOUGhhmibsVE+IzUgnEXDUFhA9GAJuDZeQ7s59W+7/OuYH2xYFYWt7EisKpth0ySXGQn5fOREifs7oR0fatVC0OsnW02rJDxKp1XsKnAEKwsbDVkz9kkeKYx6a928J0oHwjl+fA3BGIi+lakAAqROj7O21+7nh0Qw/b74Ack06c8J9lFCbEznAleYlxL4h1dw0Qe7vkPTEKme/TWWJCte6wiSZ6JjsXR98y4hIRJP6X3M6Ao2eJ3YENhpuijku0+eC15jNzwnNhduuwWYJTOgCs5pOONwxJ11A== 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=GYjCSRL/Hn961hMFw3NHAPh5b2ogFPlNjKf7ozvJaZc=; b=vWZRvyGeJ0KsCYHzGAr+vlKscGkRQsUtppCNz60gYFq/NqeauW/2Bl8dXVGmHDpHwk50eJ9AIbGWsAiQJw/PdAeRq7zWXaGFZ+fZs+urdj1bKYnn7QtHnOK3jB9P4pAWBFv64a04FDEyXDVQ2Pyy2/LNo/4N357pHL4R0sCzXBQWBkKieXnYIgpVoIyRlqJdg0LkG1qFV73FCWgpv83N5RjipAqeBFjjuVrjadQvKTwei0FQtQKwk7hvUd5Q5ujvU6OGljsVyzXE0rkdGUjyuuG/AsW9TfuH4tMh3tjlepMQAYNRJtOTsUHm6roOQioS1xTAqtafFLtsjho9fXtkbA== 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=GYjCSRL/Hn961hMFw3NHAPh5b2ogFPlNjKf7ozvJaZc=; b=apToalrwjSlIE7SRmEIK1S8gHcH1aIyQxCeGj+IqCGNzmEQ2SbJ/I+3sePgpnfsQ5yh4HYZptmeFf9njV9niI+7QTUDXXk/f7GJhPrHc3q3Cu4LVKtCGmw4N0y4wXqDWcm8hhpjAaTqsLRe8Q43Qa+wpGEGTTq6lD+WSYU52sohmHUjRm9IDP+4l0Q6N7NEw5I3O7GQzC+/+3aIA3y4mPzwMy0fOst7MustMUiREzuuFISJ8LuBq8b93DUReESrmrpScxKW1mWxCRy6rdmq4ijV9daDKtCwbR+OJIlhV9qodI3Hk2gtUFnmoLmhuLWfQijWqLbT4bOP4IGEwrjGp2A== 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 PAXPR04MB8669.eurprd04.prod.outlook.com (2603:10a6:102:21c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.21; Fri, 8 Nov 2024 19:44:00 +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.021; Fri, 8 Nov 2024 19:44:00 +0000 From: Frank Li Date: Fri, 08 Nov 2024 14:43:31 -0500 Subject: [PATCH v5 4/5] misc: pci_endpoint_test: Add doorbell test case Message-Id: <20241108-ep-msi-v5-4-a14951c0d007@nxp.com> References: <20241108-ep-msi-v5-0-a14951c0d007@nxp.com> In-Reply-To: <20241108-ep-msi-v5-0-a14951c0d007@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=1731095022; l=5357; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=SU3fKgx2Cixu2vdRhLxkwq1ELVV5yh+eHERg3ui/hfM=; b=N3iARweiI0kqEpBr2XlbgjkpHJixWh7oa8XQ1V7tpT0QkUc4grkbCqtEbgyDcYK1IRQb6Tfl1 UmhouqsOoL5A/TGNATvqakaW5/llE77/v3h5ib49hJ03skfRPwArf0E X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY1P220CA0026.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:5c3::17) 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_|PAXPR04MB8669:EE_ X-MS-Office365-Filtering-Correlation-Id: fbb97368-9f76-4f56-6963-08dd002db17b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|52116014|7416014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?7SOantg8YvNkaxt/4hzVgRzWOMPQqsR?= =?utf-8?q?48cr+fMNNCnoehk3VRnwk/GNPDv+ayfKGZZFiDk7898YqD6ceDXYcNsaorVp6WZq8?= =?utf-8?q?arPOrt/8W8DTPXVny6tBk3A+XV5rpG2A1f88tTPVgUMVE/rkZnP7AxRqhXv0BrMem?= =?utf-8?q?IQrgtfXH+yUA5dATxvge6Kj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hEZm17i3TVKxjgc62XH2edseAZzBRaeMb7xPKjcarW53+?= =?utf-8?q?B3nCYOc9BfISMbkWSNdYteQNHdKxJ94v6rnin/F411uCqtMGSsM8RpxqgoqN6JtJq?= =?utf-8?q?puAziCDPJboM5g3TrkVYxp6SrxCQ3IJ6/F3G0Yms6i+D73FIS2t5Y1KtpfdcGpX1v?= =?utf-8?q?sTW6z+5//BlLxXvTPwTw97Fr9HZMXNJ/K1ZHkE+xZesH+VcWUN+5WIaHNJIqEeUTB?= =?utf-8?q?UiXv5azWVLls9FJuyX/jNJlGMnxnvWV36IGY0KnDdYol0HBt0QtSXBAA=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)(366016)(376014)(52116014)(7416014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?doMPNUAqoyTfLKXWNsyftW17GQ33?= =?utf-8?q?cgLhp3aFlNvQHPkaGFd9R4u9RrbUJDZj5RgQXupM1wwnqSaazSSgIejEUYK9344/q?= =?utf-8?q?G2DkbV7R03POBd4IC8e1iK2NU3jMfiuCg5R5hyJC1uMZd/9tnoKknirHrHgUJdrkw?= =?utf-8?q?pPKg5DuAGFEKjV7cBnPACUH6ypS5JgRhBikKmY3d52+DRV8RrksxDS1uupQ1itaef?= =?utf-8?q?AmgPpH8rV+SddBEYwGZxUKd+z0q2ZVGem6V/zshkS+JsiOjTpzcf+JbfIlBB0NHrY?= =?utf-8?q?YjBHPXrXCnjwvma62gAIC5Xm/jitjrlJc2paEIxXROJlmZTcXGVuZuxIJ2ON82XBV?= =?utf-8?q?F1+xVoVX3QATD5xVkf7mZdUOjxlsVJ0X7WUFKsWvtpTG/o7MnxDA+/pZT1G36OzyU?= =?utf-8?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ANt?= =?utf-8?q?ali/LvMREI1WFs43Hld9lSnXiUs8oTmzI7UyOqLwiAN5GTMdjybTAP8XFPAC5hzpe?= =?utf-8?q?XGbKC1cjnsMF39EjIZNz2RHbFheVLrcz8Pv4FLKIJ7OHaTyYKrddHyYP2l6wbgPvd?= =?utf-8?q?M1nTqcUXAjtzUtkkttDRWMklIqHPr/fjpkSU2wdcobByg20wsqX0621/lTADaDtdS?= =?utf-8?q?SHCQObutUg+ipqB5xB/x6BpwxcGTapM3gN68KFuGc0xrCdxiBIyuIFftwp1PdlA4u?= =?utf-8?q?TnF6uHQEGaoe?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fbb97368-9f76-4f56-6963-08dd002db17b X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2024 19:44:00.8607 (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: skBbqxRhrs9Nxg1T0KYkY/EQMd6mv7IS6NYl+oM2j8at1xFNzAL4ObmnwWNVnKi6c8vux8uRlxitewhUcaX6PQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8669 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_ADDR 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. Signed-off-by: Frank Li --- 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..7e5741e163630 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_ADDR 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_ADDR); + 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 Fri Nov 8 19:43:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13868869 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2067.outbound.protection.outlook.com [40.107.21.67]) (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 977BE1F26E8; Fri, 8 Nov 2024 19:44:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731095049; cv=fail; b=qkuCcYkDKCB9Rr9UkKw/cAleKXMufBF/6x3JIWY0ubvx4tpxNfB/SYu+/8zgG7YqiAviPwsjn2eooIK4A0RBE/P/Fj1l2uNF0f/O4P0PUxxyBiFspyZ01CXMRZ/AzvSxrQHLXWDtxF5tyKBMYea236ufvQ1kTYyIj8uCYfQKHL8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731095049; c=relaxed/simple; bh=G/yY4CrPOouB+dXrLHUGTnxa+S7MToMCeY+wZ3vMPxk=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=F060o/jTSOXs2096380rZyOJeMPtop6d8S/L2ZNBLaBW77NubWirSGWM7h5eCskgfARov1SV+XQ6/nHnxvRb75bOAwiIFF5JmA/Fe0Ntg+j/p+TMg6ER8HMdZ8OMjHLMqqHR2fNvaH8v5NrA6MlrePMfugaURd75cw18oZuWMeQ= 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=oWno+ry7; arc=fail smtp.client-ip=40.107.21.67 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="oWno+ry7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Mm03sEtGVGeklBftXm/q+3KW71YQfG541i8vTv09+d4vERxFfnDHvFiA6W1r6EQnytMjLXVSlrixfp4op0TWpAtLno+QROPNu2WXSY51QU0smsH2LUNGGLb87uG6k2bqNLJ+9mhZmHK+fadaw7d3iEmxu2agd4zLkeR4VMnXOa7e1q1fKH9n3dVqFo5dqV7ARBAA03IJw1YlpMPA7ZMUG2GCBBFV63ChzpqOjeXDVHjlciBtBSXUmXyaPGaB143eTj1X1YYK69E+BUDeq7IMPQmVBL5C68/b/T8GpE7f32qnJzDFCc2a2BTzYYEkw1htTb/hrNr8hJNPCv51MC3iHg== 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=2yCmUQdPdUzzzBlVi0xn7vIIg3JeouJV/1R9GlTHoTA=; b=LRW3jSELVWlslW3ieYXmjJtGkCxuVJiskafB+th8HgnnC/VEK6zN1ufDY1+/akO7YtU6eOpT6MHDprMjWOOfSaLRi3QbDyss44z4l8ErVeNzmxgXG9Q2Nd6/ZglYvnogfjjmX6Ea0cZ1+tFrtcsvXDE8v16x8b7PLxvXaHkfpLTe2h1iXyppCX5RTytd3gSCFrQZIgu9xDnVaEulGHcogPw/P8tsre4wimRn7axry2gM1hFdatU/YU87DtBYiupndXvd7cmaWNFHqj2/+mJJFEh91FzJysbBKt/YtKvA2iqF/ql++RRcI3elrEK+t22l0McCGN91IIyeXp/SbAN2/g== 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=2yCmUQdPdUzzzBlVi0xn7vIIg3JeouJV/1R9GlTHoTA=; b=oWno+ry7vAoottUGg9OsdTp+0+zZ6aIZFd6Hef9YGDjw9D65ZRL8/6HppWK+NnT4P6i6V8A2AM21hySAr9h8RYgLqe5ikaAkO525wlJ4rfDebwdzxf3kMXVElOfdMc5ee9X5SXrWSVq8RN6whJDQ2jyBL1RqOPV9LwyUHR6ArTreOZ/YmwYBkMKQ84GaH11QaGG/2tsmowFQWKO8wAsvVp+BeqrCfrkBeulYWr7FQhkhIQNOXdmjnlk+bZI8gcO5DPqqWvf6pW2j1rgGnjqCnU2JiTXe8M5xeJDxL8HKWpbbcWFg3IKJhRsKrU2MZLA2kRsOyMO6/lL/q2IvqUhjXQ== 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 PAXPR04MB8669.eurprd04.prod.outlook.com (2603:10a6:102:21c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.21; Fri, 8 Nov 2024 19:44:04 +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.021; Fri, 8 Nov 2024 19:44:04 +0000 From: Frank Li Date: Fri, 08 Nov 2024 14:43:32 -0500 Subject: [PATCH v5 5/5] tools: PCI: Add 'B' option for test doorbell Message-Id: <20241108-ep-msi-v5-5-a14951c0d007@nxp.com> References: <20241108-ep-msi-v5-0-a14951c0d007@nxp.com> In-Reply-To: <20241108-ep-msi-v5-0-a14951c0d007@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=1731095022; l=1804; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=G/yY4CrPOouB+dXrLHUGTnxa+S7MToMCeY+wZ3vMPxk=; b=+BhbJy4Ltv91y3dtRF93z9RGWMXDturZTVKFbeWeCay8qN8bl7APkDApsgn4wGR6dSZAFf8xK hQwumJJCiUNCchn/1qHoOPLg/W6EBLKvnqdcEuxkNO6sjA4H6JPUR49 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY1P220CA0026.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:5c3::17) 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_|PAXPR04MB8669:EE_ X-MS-Office365-Filtering-Correlation-Id: b17fa552-e258-4918-d419-08dd002db3bf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|52116014|7416014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?fbWfcvRJS+FmmiwfGuKnCvsXxNsnTlF?= =?utf-8?q?EpgyVcU8dBHTuWDP9x3s0nibgpe4kL2SUMc3qK0IxT0xSO9FQtANkn+8Qgwy/jItf?= =?utf-8?q?MINGseRWz4JNXT7N49lw+NJJxGO9eVK92/Ui4OsbtvxBA4Ndbwl1+El/ftikUUTmq?= =?utf-8?q?eEbThm05PXeJXFA+IxCQjvdM43RZNJUFnU1RksBP3v79SL+8nN9xTfx0O+0qrpD4n?= =?utf-8?q?yzIGHYtbqYlL7y17axRD8SuJd7bPH6wDzVldM/0QOZV5hDvj7cH7zHnVcb26Uo5fq?= =?utf-8?q?P/KT8gUVaNQDUE7U+yd67/1gC4SlEYB5fGe3GKOtDdY6HzDg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I85RkcTlhCD?= =?utf-8?q?4P0kw+7bWVGPtoH9DapdQT1WLelSLhNYWry+bnATGbsf8H2IRiDv5k7eOnwHLpA3Z?= =?utf-8?q?/QrE7m2uMb3CSUyyUZ6wh4culCuRYQV89Yh2fe0Q5YJ6fp2DzzsdbA3o=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)(366016)(376014)(52116014)(7416014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?j2fFNVQ+3tA4axfYxJ6+n8fu5YEf?= =?utf-8?q?lZzi9pfZNjZIVTRPRsFwC6XoKE/em3i0bJnG4zR2u+0OsBSwZC+9F7WieMDb0a+cE?= =?utf-8?q?5vsG+367AHW4QCTTEsiPlecw9Ns7Gu53SD0WfveFMrnlM+5JMsKgWwqYmzAWCuI0i?= =?utf-8?q?JB/JmnEatVJQkaVJZ66E+krRp/Keki0WWRSZXOaFRWUCqKB62F2Y3kK2eOKF9qAUu?= =?utf-8?q?KArXTPsRN0bH1iRy8sC2f4cDUnQ2IJ3YqNNIMwwEJvLzFaTuh0FK/hWhiAMfLrIQU?= =?utf-8?q?/aw4x4vSUG+PAWlay3nW9L/JPQTwFY1CevfIvVUMNd7pLHii7D2GpUmYjJM4TdxVM?= =?utf-8?q?1Jh4mGycR916vbJwpNsYnzcMXZ3LUUGLKZkQb0t1rUJX1GBjJT86lYAViuxrFmJ/0?= =?utf-8?q?ZBzd0K313DndgASHNICG8MuJjr0ct1xtoPpzml5O3AjaMXd1mIQUKCud4h6jHBxeU?= =?utf-8?q?qpLxrO/uPLsqhy6ucA6h86An3BBisgThydN7ztbCCr9QYWlPRCi6nTngQQC+oDB7z?= =?utf-8?q?YqnxH57+BVOh7ZXjR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0MBmmMPTbqN59kOHbiP3uT6uOjMa7bSgG?= =?utf-8?q?0zYe715Rv2aMBU0+VUCRpIORyUFLW+qaLtMV2gRLhrxAjBZWRdsVFTaXL+7AY4Hrn?= =?utf-8?q?uZ/L6lDqsUBZ?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b17fa552-e258-4918-d419-08dd002db3bf X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2024 19:44:04.6595 (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: 4WmUqmDSjMStBqWL9GDTSb81J5kbpd8lNFdLQxbHWttfzR7HfcBNS7nIV/lbYsjHtcQ3zlHMeRC1lO0BKUVWoQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8669 Add doorbell test support. Signed-off-by: Frank Li --- Change from v3 to v5 - 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;