From nobody Sat Nov 23 23:44:07 2024 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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?Krzysztof_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-kernel@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|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?S2FzUTAwUTFicDV6dEhyUDl6RUd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f-8?Q?ppvV0z+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?B?dlZhbHlQamxFdzVWQ0R2ZXVTaGYxb3pIUHpZSklwL0xrU2VpYlNRMGxpdnBl?= =?utf-8?B?a1pzclFXOGYrV1hjWmdxYWFwWUU4K2IzWUNWZzRNUWYxUXlFbTJ4a0I2NlJO?= =?utf-8?B?UEgwQ3Z3Qkp6TWZKUmprbzMyWkdUamtyK3FuckNDN2lCMGtIUHJENGdJOTBJ?= =?utf-8?B?TXFjV0xLQ2FUbkRRSWhudmxJUTdiUVUvblNzcjJGMzNpTTRTcmRqN2lreHVO?= =?utf-8?B?dm5vMDhETU1abjgrcUVkZDhpMGEzVWVLWlFGc2laQ3J4ZzFucUJ0MDArVHZm?= =?utf-8?B?cTdqeGNoYklJWCtEcDZVMU84Z2RmS2VVNXBWMjg4eHNNQ0pLRDJQdDVUU1ly?= =?utf-8?B?MVpQSEdUTHlodUo2dmE1VXNRbGhsRXpQOS9GMHQ5OTZQNVQ5VWREYlZrWFg4?= =?utf-8?B?NVV5a3FLSFNJeFBUVStZUDBLZ3IxRXA2Z0hFQWptNEw2TWY3d1ZIcHVqRDFO?= =?utf-8?B?SzhEa1g2UW5abC8rY2NuQUtaTjI3OFNUTVl3ZThoaXRiQ1V2RVd3bVcvUGda?= =?utf-8?B?U1JkL1NYSWppOEF2aC9HR0tDNGhTa0ZTU3ZjWTFDckxTQTErcGpSUXhPazRq?= =?utf-8?B?Zk12c0RrKytOSktqY2pSbUpvLzJLN3NlcVNVVWppUGtLb05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nVC9waWRCbmt1NU1qc0Vl?= =?utf-8?B?NThoKzZoQ3V1M3RIN21nUzBPa0RTSmVOTEh3UmpPMllZK1hjcHFJbUVuZVdj?= =?utf-8?B?eUJIa0l4VVVsQnROc25PeGl1bTlLb0Z0djltYlN1cWZTZGNIT2JkNGRyL2Rm?= =?utf-8?B?NEdBQ3psU2RrNkZadzgrV1Bpdmo0SHJZeGJUR0NxazBubmQ2U3hKY0pJcUVi?= =?utf-8?B?aDVSeXNGQjdCeGlFTGRkTm5ucjF3WWx5YnpNVmpUUWk3MXBFTVhleU9XdFdS?= =?utf-8?B?MDA5NHV1c2l4UnNLdHdrSFlEUURoNUU4MWF2c05nQis1SW9TdURXc1hzakVS?= =?utf-8?B?NkdxM3pNd3ZraE9rN1pRZ083QXF3L0pwTmVnSkNld2pNbk5lUlRpRnVPSGFM?= =?utf-8?B?RlVDRVNvRHcwTmhLNUY4MUhkR0pBTGpocjh6SlBLQXdRYmQ4ZU9yd3VtS2R5?= =?utf-8?B?ak1MOTB6em1wMnJNTlh6emRaSkowZ1BvY3JoUWsreGlKWHJKL0lBSTg5YXNS?= =?utf-8?B?QUs5Q0RMdFdZSkZhR3Y3ZTlIcXBKeFpzc0pMRGgwc3NjTjUxakJJN2c1RSt6?= =?utf-8?Q?lfY8pEW2GfvXvfD/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 Tested-by: Niklas Cassel --- 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); =20 +static bool pci_epc_match_name(struct device *dev, void *name) +{ + return strcmp(dev_name(dev), name) =3D=3D 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 =3D -EINVAL; struct pci_epc *epc; @@ -64,7 +83,7 @@ struct pci_epc *pci_epc_get(const char *epc_name) =20 class_dev_iter_init(&iter, &pci_epc_class, NULL, NULL); while ((dev =3D class_dev_iter_next(&iter))) { - if (strcmp(epc_name, dev_name(dev))) + if (!fn(dev, param)) continue; =20 epc =3D 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); =20 /** * 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_feature= s *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)) =20 int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t base, size_t size, size_t page_size); --=20 2.34.1 From nobody Sat Nov 23 23:44:07 2024 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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?Krzysztof_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-kernel@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?B?WitESjZDYXNob2lVakg2cHVkVmdyVVlSRmYzdXVBd2tlTldUbm03bk9qSXZt?= =?utf-8?B?ekNFZGdxdk5nZGlOQ3JVbEF0bG5zWHhPd2hyN0tzZyswMURZZVo0Zno3V3dB?= =?utf-8?B?MmM1bmlnUzNNeUZOL1ZEZE50SGxSTHZsT2U0M2dWUGRZWTBOUDMybU5Rdzkv?= =?utf-8?B?akVsTGtGVXhia2NOelh2cUhlSFR1UUtkUE5EeWdBSGNXQzcxa3IwdmpMNEI1?= =?utf-8?B?K2UwOUh1V3E4OVlIZDU4NmxYejJHNXhsTGh0djFNRkkrTUlZdDZEaTdUc0pt?= =?utf-8?B?bk9VaHJFVkhKa0tuOGJacjdmWlhTNjdqb1RERWZpRzZyQitJcXp5Nm4vVkFu?= =?utf-8?B?a3Z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utf-8?B?T0hpb2xBcE1GZmRWK1RRcTdKUGczNEJ2b2U3djFUb1pKMVVjajBNYi9BbEV4?= =?utf-8?B?WWxVMkltckhCMFFNMU4vY2FVZjhaUy9pQURRaklqNmd3aFBRcGQwS2dtMkVR?= =?utf-8?B?ZFNJTGlGdU1STjVwWHVnd2V1RmZIYnJpN25JOUtUOVg3NUJ3cXFUVWJCeFNy?= =?utf-8?B?Z0E5VG1hb05HQS82RDR0MHB4QUVFdUVhMkFpbytOZXFjYkRWRnRSK2J0a2la?= =?utf-8?B?bWtqVGFoRkZ2Tng4Qy9GQWxNb0R3bFN1WjFFUEZNZDNwUGVmWitFcU5PaTRW?= =?utf-8?B?VHMvSnlqU0VxbGRkdm9IQ1RzWHdvV0Ezcm8zUlVlbWdReVFYTkFaUjNyUXg5?= =?utf-8?B?dHdUNmI2U0YwZWFLeDB6K2h0K0haY1ZSNVdnSlVGYVRKN2JDUmg4NjREYnM3?= =?utf-8?B?ZkszWEVVU1RhbjVRN25mWGRjRDJVL0Z2SU8yeGljb2R1NGVNM2drZFR3aElU?= =?utf-8?B?cjEwS3hJTjNSOFR3bmZramNvN25hR0hueGVsd0FOSFVEWG8rREd0OW5rY3cv?= =?utf-8?Q?vEgYJWk82hSg1Inwl4C1/S1SsW2e7M0bqgSAY=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?B?QTRhcW9NMGhlTE8rNUpVd3FicTNjWUI0SDFscTRaK2ptclR4TWF3aTNUWDV0?= =?utf-8?B?Z3RDNXk5aHRqSUFqclhXQlBnSnJpYjZncmlqaTJ0MnR2aHBaZzJNdk5Hb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xUNmcwdXJnNHkveXZld0psQnZIZ050R1l2c0Y3?= =?utf-8?B?bDhnVUViUmtPUzRkMVNLUm9LWWo2TGhIUkFsQU1jREdITktJQlo3MHRtbk1L?= =?utf-8?B?NU5YUXNuVkF5WHY4ZjdwbFVUV20zcjRVbnVWb0xaUzhKd1Q1enlaTE1mTmNm?= =?utf-8?B?YlJwVTM5aXI3KzdoNVR3bXpzTGJKR0licXdwL3FaTkVsZTY5L0J3cC8zU3Yr?= =?utf-8?Q?XoM5UFfKYztzN1q2nUworJl0N?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-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 Tested-by: Niklas Cassel --- 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 @@ =20 obj-$(CONFIG_PCI_ENDPOINT_CONFIGFS) +=3D pci-ep-cfs.o obj-$(CONFIG_PCI_ENDPOINT) +=3D 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-e= p-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 =3D=3D param; +} + +static void pci_epc_write_msi_msg(struct msi_desc *desc, struct msi_msg *m= sg) +{ + struct pci_epc *epc __free(pci_epc_put) =3D NULL; + struct pci_epf *epf; + + epc =3D pci_epc_get_fn(pci_epc_match_parent, desc->dev); + if (!epc) + return; + + /* Only support one EPF for doorbell */ + epf =3D 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 =3D epc->dev.parent; + u16 num_db =3D epf->num_db; + int i =3D 0; + int ret; + + guard(mutex)(&epc->lock); + + ret =3D platform_device_msi_init_and_alloc_irqs(dev, num_db, pci_epc_writ= e_msi_msg); + if (ret) { + dev_err(dev, "Failed to allocate MSI, may miss 'msi-parent' at your DTS\= n"); + return -ENOMEM; + } + + for (i =3D 0; i < num_db; i++) + epf->db_msg[i].virq =3D msi_get_virq(dev, i); + + return 0; +}; + +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 num_db) +{ + struct pci_epc *epc =3D epf->epc; + void *msg; + int ret; + + msg =3D kcalloc(num_db, sizeof(struct pci_epf_doorbell_msg), GFP_KERNEL); + if (!msg) + return -ENOMEM; + + epf->num_db =3D num_db; + epf->db_msg =3D msg; + + ret =3D 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 =3D epf->epc; + + pci_epc_free_doorbell(epc, epf); + + kfree(epf->db_msg); + epf->db_msg =3D NULL; + epf->num_db =3D 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 =20 struct pci_epf; @@ -125,6 +126,17 @@ struct pci_epf_bar { int flags; }; =20 +/** + * 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 func= tion * @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; }; =20 /** --=20 2.34.1 From nobody Sat Nov 23 23:44:07 2024 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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?Krzysztof_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-kernel@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?B?RmIvQmZ3SDFhNks0WXBKelFtdTdaZ0N2bkZFT0Ztdy9EWXYvTndkNkNxTjlD?= =?utf-8?B?eWplTENMenAyQkFqenUrNUYxSTl2RUdoVFp5ay8yNjQrL0Q4ZzFjSGczdDBV?= =?utf-8?B?WnVIbFZHUFRGc1U0dWRPNjYrSjNHYmpIN2laeEM2UXc4NnZjWWl5dzI0bXFF?= =?utf-8?B?enFqTDhoMFhLVDNMTHA0SGRDcGRNUytBOE9STkIxRkRHRC9zV1hXNEM1S3px?= =?utf-8?B?VVNTRHVLVEZESlhiMTY1NUd1SXN2aWxtbzlSZW9jR2JrWG5LMjQwSi96b1pp?= =?utf-8?B?S3krT3FaU0VVcndhOUJOTWx6UGEyRXYwN2FsaHVlT0tXbk9pRy90NGlmSnJM?= =?utf-8?B?UDJ5blhta1pHZ3JzZ1VDa2RTbTlTSitKcmpkS09ZTTU1Q205Z2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SEh3clFoRVhzN2JTY2Np?= =?utf-8?B?ZU5aQVNKTVBTWm9oNHZVVUpmb0x4djQxWEZOU3BGbHBUL0VvOUNhbGJBbi9K?= =?utf-8?B?R0ptT1N2UlZZVlV4WnFVRnM5eHlwR2haMWJQS2Ryem40OHhTRzVxMmRpNnNY?= =?utf-8?B?Skw3bUhmaDJINGVMSys0bjEyeGxJaFQxMC9KTkoxNHU1d3RkSWZ4amVRR0lz?= =?utf-8?B?VEprUHRpQTl3UjFUVGltaGcvK2trWjMwS2p3bjBBMWU4bGhRaUdveDArc2lq?= =?utf-8?B?QVg1YlQ5bldOS3F6RVhxQ0J6S1RHMlhML00rM1JXdUUwMXBVcHBURlFsZDlP?= =?utf-8?B?UjgydzRxTmNOSk5IbVpDNk95ZzF3QWZ3ZDNtMzUzeW5JYkFZcElodHg3ajl1?= =?utf-8?B?dFFwV2pGVEFjVjNaUWRUWGVqcVNydE95VW94TFlWM2hHbjlMamxmb2t3c1Rn?= =?utf-8?B?ZGo4TVE5NGhSaW1LT1V4VVhMemE2ZjNVaXNVLyt1SWNWNllFb09GMDVJSFJi?= =?utf-8?Q?PogKiFy5RekzOKn1271oylF8R7xpBBhW2VhYo=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?B?Y0JOL0wvUFlvQ0lXWi9QNlZQKy90c1dWV0tnTk1COWE0Q0FPK2pERENoV0pM?= =?utf-8?B?M2lYazZmdE12R3k1aFNqdmw1eHJMNW1KejVqd0xlMWpzTVJJRnlNVDcyR245?= =?utf-8?B?dmJRUXVxTWpZMjB5dlFSaHVWWTBQbE1xQ3ZDdzh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?S0FkQzZiWjRvQ2RMUWI3YlA5dFNINmh0T0NiU2J1M3JMdHRYUy9rNEhhOTVa?= =?utf-8?B?bTIxVW41UU9EQU1aWGtkZVRIZ0dZUGppeHR5K0sydHllVFZKYndxY1NsT3lE?= =?utf-8?B?aGlYbnFtK0VzMmtSdUUrM2REWE9wa0h2T1E0UldVN2Fyd1NncGo1THVBK1Vs?= =?utf-8?Q?OiemBF+dp4CRY6wW6+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 Tested-by: Niklas Cassel --- 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/en= dpoint/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 =20 #include #include +#include #include =20 #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) =20 #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) =20 #define FLAG_USE_DMA BIT(0) =20 @@ -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; =20 static struct pci_epf_header test_header =3D { @@ -630,6 +642,63 @@ static void pci_epf_test_raise_irq(struct pci_epf_test= *epf_test, } } =20 +static void pci_epf_enable_doorbell(struct pci_epf_test *epf_test, struct = pci_epf_test_reg *reg) +{ + enum pci_barno bar =3D reg->doorbell_bar; + struct pci_epf *epf =3D epf_test->epf; + struct pci_epc *epc =3D epf->epc; + struct pci_epf_bar db_bar; + struct msi_msg *msg; + u64 doorbell_addr; + u32 align; + int ret; + + align =3D epf_test->epc_features->align; + align =3D align ? align : 128; + + if (epf_test->epc_features->bar[bar].type =3D=3D BAR_FIXED) + align =3D max(epf_test->epc_features->bar[bar].fixed_size, align); + + if (bar < BAR_0 || bar =3D=3D epf_test->test_reg_bar || !epf->db_msg) { + reg->status |=3D STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + msg =3D &epf->db_msg[0].msg; + doorbell_addr =3D msg->address_hi; + doorbell_addr <<=3D 32; + doorbell_addr |=3D msg->address_lo; + + db_bar.phys_addr =3D round_down(doorbell_addr, align); + db_bar.barno =3D bar; + db_bar.size =3D epf->bar[bar].size; + db_bar.flags =3D epf->bar[bar].flags; + db_bar.addr =3D NULL; + + ret =3D pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &db_bar); + if (!ret) + reg->status |=3D 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 =3D reg->doorbell_bar; + struct pci_epf *epf =3D epf_test->epf; + struct pci_epc *epc =3D epf->epc; + int ret; + + if (bar < BAR_0 || bar =3D=3D epf_test->test_reg_bar || !epf->db_msg) { + reg->status |=3D STATUS_DOORBELL_DISABLE_FAIL; + return; + } + + ret =3D pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &epf->bar[bar]); + if (ret) + reg->status |=3D STATUS_DOORBELL_DISABLE_FAIL; + else + reg->status |=3D 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_struc= t *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; } =20 +static irqreturn_t pci_epf_test_doorbell_handler(int irq, void *data) +{ + struct pci_epf_test *epf_test =3D data; + enum pci_barno test_reg_bar =3D epf_test->test_reg_bar; + struct pci_epf_test_reg *reg =3D epf_test->reg[test_reg_bar]; + + reg->status |=3D 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 =3D { .epc_init =3D pci_epf_test_epc_init, .epc_deinit =3D pci_epf_test_epc_deinit, @@ -909,12 +998,46 @@ static int pci_epf_test_bind(struct pci_epf *epf) if (ret) return ret; =20 + ret =3D pci_epf_alloc_doorbell(epf, 1); + if (!ret) { + struct pci_epf_test_reg *reg =3D epf_test->reg[test_reg_bar]; + struct msi_msg *msg =3D &epf->db_msg[0].msg; + u32 align =3D epc_features->align; + u64 doorbell_addr; + enum pci_barno bar; + + bar =3D pci_epc_get_next_free_bar(epc_features, test_reg_bar + 1); + + ret =3D 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 =3D align ? align : 128; + + if (epf_test->epc_features->bar[bar].type =3D=3D BAR_FIXED) + align =3D max(epf_test->epc_features->bar[bar].fixed_size, align); + + doorbell_addr =3D msg->address_hi; + doorbell_addr <<=3D 32; + doorbell_addr |=3D msg->address_lo; + + reg->doorbell_addr =3D doorbell_addr & (align - 1); + reg->doorbell_data =3D msg->data; + reg->doorbell_bar =3D bar; + } + return 0; } =20 static void pci_epf_test_unbind(struct pci_epf *epf) { struct pci_epf_test *epf_test =3D epf_get_drvdata(epf); + struct pci_epf_test_reg *reg =3D epf_test->reg[epf_test->test_reg_bar]; struct pci_epc *epc =3D epf->epc; =20 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); } =20 --=20 2.34.1 From nobody Sat Nov 23 23:44:07 2024 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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?Krzysztof_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-kernel@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?B?N1NPYW50ZzhZdk5rYXh0LzRoelZnUnpXT01QUXFzUjQ4Y3IrZk1OTkNub2Vo?= =?utf-8?B?azNWUm53ay9HTlBEditheWZLR1paRmlEazc4OThZcUQ2Y2VEWFljTnNhb3JW?= =?utf-8?B?cDZXWnE4YXJQT3J0LzhXOERUUFhWbnk2dEJrM0ErWFY1cnBHMkExZjg4dFRQ?= =?utf-8?B?VmdVTVZFL3JrWm5QN0F4UnFoWHYwQnJNZW1JUXJndGZYSCt5VUE1ZEFUeHZn?= =?utf-8?B?ZTZLajBwajNqaDhDWlVjNXd0NEpQOEVYWUdTRjRQZERUc3VlR3RlSUVMdkpk?= =?utf-8?B?MG45NDNrWFdXMVgxckt0TjlramU1T3oxMHk5MGRmZS9ycngwdjNOSWNRUjhH?= =?utf-8?B?NEpnL01EbGtGZmNlTENNQWlBZEk2UENYeUdUUjBLM0h3Y3pIUGNteXBtK2hk?= =?utf-8?B?Rm0rU29Cbk96Y0xobWZkRnNPemhubzFRdzZOazlQODhvSkV5QUFVdXhWOGFi?= =?utf-8?B?N084M09hdkgyQVg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B?d3k0YUViaVpuWGJJaWs2aHhqVUR0cHhjWk1xK3lHLzlNY2NPYTJnWUxia2tD?= =?utf-8?B?Q1RTeTJzajM0cUxoRVptMTdpM1RWS3hqZ2M2MlhIMmVkc2VBWnpCUmFlTWI3?= =?utf-8?B?eFBLamNhclc1MytCM25DWU9jOUJmSVNNYmtXU05kWXRlUU5IZEt4Sjk0djZy?= =?utf-8?B?bmluL0Y0MTF1Q3F0TUdTc004UnB4cWdvcU42SnRKcXB1QXppQ0RQSmJvTTVn?= =?utf-8?B?M1Rya1ZZeHA2U3J4Q1EzSUo2L0YzRzBZbXM2aStENzNGSVMydDVZMUt0cGZk?= =?utf-8?B?Y0dwWDF2c1RXNnorNS8vQmxMeFh2VFB3VHc5N0ZyOUhaTVhOSi9LMVpIa0Ur?= =?utf-8?B?eFplc0grVmNXVU4rNVdJYUhOSklxRWVVVEJVaVh2NWF6V1ZMbHM5Rkp1eVgv?= =?utf-8?Q?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?B?ZG9NUE5VQXFveVRmTEtYV05zeWZ0VzE3R1EzM2NnTGhwM2FGbE52UUhQa2FH?= =?utf-8?B?RmQ5UjR1OVJyYlVKRFpqNVJnUVh1cE0xd3ducVNhYXpTU2dJZWpFVVlLOTM0?= =?utf-8?B?NC9xRzJEa2JWN1IwM1BPQmQ0SUM4ZTFpSzJOVTNqTWZpdUNnNVI1aHlKQzF1?= =?utf-8?B?TVpkLzl0bm9La25pckhySGdVSmRya3dwUEtnNUR1QUdGRUtqVjdjQm5QQ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VEFEYUR0ZFNTSENRT2J1?= =?utf-8?B?dFVnK2lwcUI1eEIveDZCcHd4Y0dUYXBNM2dONjhLRnVHYzB4ckNkeGlCSXl1?= =?utf-8?Q?IFftwp1PdlA4uTnF6uHQEGaoe?= 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 Tested-by: Niklas Cassel --- 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_t= est.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) =20 #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) =20 #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 =20 #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) =20 #define PCI_DEVICE_ID_TI_AM654 0xb00c @@ -108,6 +119,7 @@ enum pci_barno { BAR_3, BAR_4, BAR_5, + NO_BAR =3D -1, }; =20 struct pci_endpoint_test { @@ -746,6 +758,62 @@ static bool pci_endpoint_test_set_irq(struct pci_endpo= int_test *test, return false; } =20 +static bool pci_endpoint_test_doorbell(struct pci_endpoint_test *test) +{ + struct pci_dev *pdev =3D test->pdev; + struct device *dev =3D &pdev->dev; + int irq_type =3D 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 =3D pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + if (status & STATUS_DOORBELL_ENABLE_FAIL) + return false; + + data =3D pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_DATA); + addr =3D pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_ADDR); + bar =3D 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 =3D 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 =3D 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 |=3D 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 =3D pci_endpoint_test_clear_irq(test); break; + case PCITEST_DOORBELL: + ret =3D pci_endpoint_test_doorbell(test); + break; } =20 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) =20 #define PCITEST_FLAGS_USE_DMA 0x00000001 =20 --=20 2.34.1 From nobody Sat Nov 23 23:44:07 2024 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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?Krzysztof_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-kernel@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?B?ZmJXZmN2UkpTK0ZtbWl3Zkd1S25DdnNYeE5zblRsRkVwZ3lWY1U4ZEJIVHVX?= =?utf-8?B?RFA5eDNzMG5pYmdwZTRrTDJTVU1jM3FLMEl4VDB4U085RlF0QU5rbis4UWd3?= =?utf-8?B?eS9qSXRmTUlOR3NlUld6NEpOWFQ3TjQ5bHcrTkpKeEdPOWVWSzkyL1VpNE9z?= =?utf-8?B?YnR2eEJBNE5kYndsMStFbC9mdGlrVVVUbXFlRWJUaG0wNVBYZUpYRkErSXhD?= =?utf-8?B?UWp2ZE00M1JaTkpVRm5VMVJrc0JQM3Y3OVNMKzhuTjl4VGZ4ME8rMHFycEQ0?= =?utf-8?B?bnl6SUdIWXRicVlsTDd5MTdheFJEOFN1SmQ3YlBINndEelZsZE0vMFFPWlY1?= =?utf-8?B?aER2ajdjSDd6SG5WY2IyNlVvNWZxUC9LVDhnVVZhTlFEVUU3VSt5ZDY3LzFn?= =?utf-8?B?QzRTbEVZQjVmR2UzR0tPdERkWTZIekRnMngxR1NndVFmdnZp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VVzc29mQ2x0eStVSWloS284S0sxUTlR?= =?utf-8?B?dnFwRFJTSnVEb3JRR0ZobjJCWmNoMjFmVCsyL2RDS0Z3dG9nNEo5QitXZmN2?= =?utf-8?B?em9Cb0RJLzNVL1BXMW8rTkROVGoxNFJhZTZLcGJhaEpETmx3NHEzTEx6ak9R?= =?utf-8?B?OEFGeHY3VUdaekxzanh3eGxpenUxQkRjV2l5SjlwODhoVzE0Yy9QYjY4UHI3?= =?utf-8?B?MHZzcjdKUlVmMmtMa1k5Mk1tV0QvaFpnZ0pYYmRxNDM5ZmtkdFl4RVZiTXpG?= =?utf-8?B?eWM4YnhJNWFvSTBGSUxVS0FiR3VpOGpHL1R4RnVBRnk0Zlo3Q2JXSEk4NVJr?= =?utf-8?B?Y1RsaENENFAwa3crN2JXVkdQdG9IOURhcGRRVDFXTGVsU0xoTllXcnkrYm5B?= =?utf-8?B?VEdic2Y4SDJJUmlEdjVrN2VPbndITHBBM1ovUXJFN20ydU1iM0NTVXl5VVo2?= =?utf-8?Q?wh4culCuRYQV89Yh2fe0Q5YJ6fp2DzzsdbA3o=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?B?ajJmRk5WUSszdEE0YXhmWXhKNituOGZ1NVlFZmxaemk5cGZaTmpaSVZUUlBS?= =?utf-8?B?c0Z3QzZYb0tFL2VtM2kwYkpuRzR6UjJ1KzBPc0JTd1pDKzlGN1dpZU1EYjBh?= =?utf-8?B?K2NFNXZzRyszNjdBSFc0UUNUVEVzaVBsZWN3OU5zN0d1NTNTRDBXZnZlRk1y?= =?utf-8?B?bmxNKzVKTXNLZ1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VVFcHMvdVdR?= =?utf-8?B?WkI2WWIwTUJtbU1QVGJxTjU5a09IYmlQM3VUNnVPak1hN2JTZ0cwelllNzE1?= =?utf-8?B?UnYyYU1CVTArVlVDUnBJT1J5VUZMVytxYUx0TVYyZ1JMaHJ4QWpCWldSZHNW?= =?utf-8?Q?FTaXL+7AY4HrnuZ/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 Tested-by: Niklas Cassel --- 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; }; =20 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]); } =20 + if (test->doorbell) { + ret =3D 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 =3D "/dev/pci-endpoint-test.0"; =20 - while ((c =3D getopt(argc, argv, "D:b:m:x:i:deIlhrwcs:")) !=3D EOF) + while ((c =3D getopt(argc, argv, "D:b:m:x:i:BdeIlhrwcs:")) !=3D EOF) switch (c) { case 'D': test->device =3D optarg; @@ -222,6 +232,9 @@ int main(int argc, char **argv) case 'd': test->use_dma =3D true; continue; + case 'B': + test->doorbell =3D 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; --=20 2.34.1