From nobody Fri Nov 22 15:45:41 2024 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013052.outbound.protection.outlook.com [52.101.67.52]) (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 35A2617C61; Sat, 16 Nov 2024 14:41:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768071; cv=fail; b=lKTg4q96nNWYgxAgB3BXaNRDuRq2sArjrPPtxzO4D0dJ2ZCfdaF1apSIrNt3VV+3Krgd64vELG8OFZJnpcZ3FHQ2my5/bz+6okahWXyeM0vG7Ovy6J9wTj88MTZ+ohxDyE4sLaKYu7iAQP069DoJXcgXEe0mOTTCHnOEF9mIuPE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768071; c=relaxed/simple; bh=ddQJGOgVqT+GFgYeTaZpLu0yEfEdWMMFBmUhAfO/2D0=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=VH9LjnWMlyjIJeBL1Fw7hL64VOYfOwTCNHfC3mf1R/YxS4txysRvRZNnAa1dphMbzm5PJ21EXZp2MSar9ewfRG5R5DUtNGe4PVC9H6bAozYmJg1DvaLFK2T+iuLYnsxNDIA18ibCkGCPPU67G/LCCujjdOsNBgEZ4Xoy5dy55gs= 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=Z58OAdVb; arc=fail smtp.client-ip=52.101.67.52 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="Z58OAdVb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=s2expSynKsyytdb4fzV5R6TB15t+hBvwSnaNC0om07ZalP90VWum1MgCW3VYz1Z7h9r5JV48UA+Y8Nn0u75lDEnd/oSc6haQ/Dbfkg8dc+qGsXSHW5XV3w2Hs6/CmcJIDJKXxPv4GwGu8lqFcyjRLQyHky00a5giAKvynRSleGRcc3SCVs3UirGh3TrsYbqz0tdqqGmzS9Mbuuq+HF3tX72aQm8x1RlDUu1hJ3YCZ2PfHLZw5dcHE2/gbnRCoZ28lPCF8DXUgDyQV+44EFykN9hcwEwgYYk7Evt4rubW/GNjTeESs33KXHi2tuuwEUf247e/reMPnqx3Nic/MzTRtg== 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=uuDh6IPej+1IZb3dyW/IgKJh0HGNgajYdvzA9re1UFo=; b=ZN+ErnvkayKuYasKjNFcO8kI2DEhDu4k0sZQghaTL8gXCw1uB/T7v7e4YfqFZx74xdxrWpzAckEi5T/wYHrs5A0sOuawhUiu0LSFG9WjKD2jahej723VT3F/sJkNDZ9R79cY7P989g99nQuPKCX3UFvL2Ljz3P50Kc/LsnR1DjCSvVW3lFYHyZDH/91vl6EfFKdyVUhmXlkNjFsy8jP5XIvHjEsDJHcoWcRsQsfKHqFWgUDjMNojyuhghLbHZD04fCVcFxxUdnl5G7UHsNadgsTpy221YqRXWRd409rxtnzqAn44LI/5BS/ihXJBLQww4rjxB1WMjJQjBWZcM0r73Q== 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=uuDh6IPej+1IZb3dyW/IgKJh0HGNgajYdvzA9re1UFo=; b=Z58OAdVbyeK8UF+6CkzovPGv0cxJ4q+AWg5wxJZ6aJ7pzj2tqlqOIQfDbdJ5wwsi3zZ2H0l91PStt8pQBM4krq3povx1pQdhSfeJFt+5DoCtspCGZCRIJ2yRkPOlDK9U/ivWwxuLCZKvrP91IjDOMEYoSu7wOqoCDVqRMk9NKiS2R8VGMu8PF+4IbE9xMeMsw2VU1sIE7/p77L6YAcONi2tMpj+1q+PKyjl9RrNI3MXOj2bafDaHpG83qsshJJ9jsIj/jFlGXIwj4ifJ3+5J7re8Gxeruzd7XkGRhbQDAPwKuda4qUykWze34J3vf2eDvhALqaPAGf4UNSqVXy7/Lw== 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 AM8PR04MB7265.eurprd04.prod.outlook.com (2603:10a6:20b:1d8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.21; Sat, 16 Nov 2024 14:41:05 +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.8158.017; Sat, 16 Nov 2024 14:41:05 +0000 From: Frank Li Date: Sat, 16 Nov 2024 09:40:41 -0500 Subject: [PATCH v8 1/6] 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: <20241116-ep-msi-v8-1-6f1f68ffd1bb@nxp.com> References: <20241116-ep-msi-v8-0-6f1f68ffd1bb@nxp.com> In-Reply-To: <20241116-ep-msi-v8-0-6f1f68ffd1bb@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=1731768057; l=3147; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=ddQJGOgVqT+GFgYeTaZpLu0yEfEdWMMFBmUhAfO/2D0=; b=dXe9DHNGqYLK+qXJ2TN3yOPspSfJDJxkPRLRNRLERHxH8JKxDZSImzBlBlcstbyHCxB/ouU5p zH+un8sDzAvBfsES4zxwH9bSQbt1JkFhgWGdEwcasiQtoECyDcdeMHD X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0210.namprd13.prod.outlook.com (2603:10b6:a03:2c3::35) 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_|AM8PR04MB7265:EE_ X-MS-Office365-Filtering-Correlation-Id: 1f56f913-096f-4c86-7a71-08dd064cb31d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|7416014|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?B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?= =?utf-8?Q?Riz8ynxCVAZssPDo3RF3cy3YU/6wI6KG84H1I=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)(52116014)(7416014)(376014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?TE1rSDV5ME5MdTZ1K2RkMlZxdlFRRUtwSkUycXloVzhhandkSWZUSjFpVXdD?= =?utf-8?B?aTcrRGdYZVpDVVFKajU4dVQ3cXNoZXR1azlKY0tHVWF6QXVWRzdrNjBHa3NT?= =?utf-8?B?c2ZNOTRnZTJQNVIwb0ZQeHlidStlcmo0d3V6TVpQY0tHbTdxTS9pTCtNRDM1?= =?utf-8?B?amdHNFJhWmxZL1pmamVhQmNUUDFLK0Z6V0lBRkVia1ZEdXo3dHNzY2pUZ01v?= =?utf-8?B?cW4vazJPOE1tbGFyWUxudmVzcWNJeFNJOTdjek1uRkRJcjVISmZBY0V0c3F2?= =?utf-8?B?ekxoUWsxUHBFY0NNNjdkVWo1ZVAvY0k1RWQ3UFpNVGxvVVZ5MVVlbnVQWWNN?= =?utf-8?B?Z0Fkd2d6U3MrM1pubXVlOVZ1WlpuVjltTUFQTTVTdUR2OU03UUdTOVN1SEpT?= =?utf-8?B?VC9RdFlEM3luNjgxeENDOEh2NHM0K0NYSWlrSThhQ1Y1SlJ1Mk14eFpMdzQ1?= =?utf-8?B?eU90ZUtTZmtPcFhPdWQ3N1ZyMEs5SFNrY1hyd3Q4UWxvanhETkVVQ0JsRy9y?= =?utf-8?B?NXUzMS9KNnlyenk4QXkwMGdFTSsrU2lvR3JpOURhbVZPc05pMTlMN1k4RkhZ?= =?utf-8?B?YVVBT2ljL0ZtdGpHNkU3Q3FEOGdDa3lab0xLQ0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MFJSREFncjdMS3ZpMjUw?= =?utf-8?B?cGhDcU1uRFRjQ09WUzZ5R2V3VkFUbUt5eVZ3ODFQZ3p6cys1OENCeDYveEUv?= =?utf-8?B?aFhuQlJkcWIyL2VnVGl3VjVqTDYrU0M0cEhMbHlHVit2cHpjcm9icmYrV1FG?= =?utf-8?B?NDlLR2htcEFiK09iQUp3ZHRpRG9mZjQ1bkRZTFpsK0MrSFJqQlI5WC9TQ3oy?= =?utf-8?B?OXA3dkpSUUZFZGNaTzBIYTRPVTRPL0IyMnBEZUsyWHZTd2pkT0hhdVNGazZU?= =?utf-8?B?c0RTZUlMeUtWLzZRZ0pFRUZEUWNFYmlVS0JiVUd5YnZaenplcnF1bzZna3Zs?= =?utf-8?B?eGJqRnk5a3hGa1lJaG00R1krZlBXSmFhR0dBQmd0SVhacWxQK2JWbmFtU3hq?= =?utf-8?B?WnVIbHVxcnp2R2h1SFhXcnd1WjZjSyszM1cvMFdHbHhGZXN0N2I2dmh5WmdO?= =?utf-8?B?OTN5ZlpuTjF6ek9Bekt4cG5QRUYxUmt1RjZqU24rTnBqb3diZzFXWHNXLzJZ?= =?utf-8?B?RSt3NTJEaGlsS052ZXZZZTdldjJTZEF3S0R3OHNzYnFPeVhhMnZxcHBHbFB2?= =?utf-8?Q?axnQ=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1f56f913-096f-4c86-7a71-08dd064cb31d X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2024 14:41:04.9634 (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: 2eBvPdj+gRWFU5d2hJMWl5AILsfRaMWlyXQlR/I3HNLTAe+TMgFrwt7YNg/vlw5kRWtQeu9htdwW2wQATM0m3Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7265 Introduce the pci_epc_get_fn() API, allowing a custom filter callback function to be passed. Reimplement pci_epc_get() using pci_epc_get_fn() with a match name callback. Prepare the codebase for adding RC-to-EP doorbell support. Add DEFINE_FREE(pci_epc_put) to implement scope based auto cleanup. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- change from v3 to v8 - none --- drivers/pci/endpoint/pci-epc-core.c | 23 +++++++++++++++++++++-- include/linux/pci-epc.h | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci= -epc-core.c index bed7c7d1fe3c3..f5538c007678e 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -48,6 +48,11 @@ void pci_epc_put(struct pci_epc *epc) } EXPORT_SYMBOL_GPL(pci_epc_put); =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 de8cc3658220b..d3d3b8c914614 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -300,7 +300,9 @@ pci_epc_get_first_free_bar(const struct pci_epc_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 Fri Nov 22 15:45:41 2024 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013052.outbound.protection.outlook.com [52.101.67.52]) (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 85B297BB0A; Sat, 16 Nov 2024 14:41:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768073; cv=fail; b=ZCunFCx89ebGRRMv9vCBKFc1yGYdCIOOVgd2YKslVPX5fvMzkujh+7lJKOy8oSjWEZGriVRYWBjaxUV59wdhMmqoKeBCS8adY16KGsimG102O3eCteSM0DRC9fOOH9ySTES6J6QKO8OrlxAFXTSFn5mif9RYN36ETeOeC75FyUM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768073; c=relaxed/simple; bh=/7Pai0goKHvPIK+tBY0qEDaD68qr8tke0aMwrO4/bPg=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=ATyqAq4f8LrmuOqAEVKJgASa1jxaViVkDhRhi3BDxRWzLNoxUDhnX7JepnK+KXRpWD7RLEHeEyQeETzmDTGxLooggYz7td7OVbG7hBphajH+Trmf6lara5Tr82W+8hcuRDQgmV0s+p5l9nHp/UwzGzkE8H20QWvuoWrmTWkmK9s= 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=VYLo6CEC; arc=fail smtp.client-ip=52.101.67.52 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="VYLo6CEC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cG9PPusefQ5OmzuxUgymceolTmwb2bgqaYcJPBMg9qUJi6OSp8tfiIfuu9GWIh1QfWvVkdA3nOR2LLD2qf3yV07NEv3QCgIF3RWXRvZiqfCSAkPFlnNy8dLVjDOJZ10bQxopPaLH8tw+oWX+ahZWNlr4/iTv4MtyJ2grgqMPHKy1R9bHxXW+1B2y92SGt47QnliY7Tm6DsyClnY1FWB8U1vlSsBsy2zv7unbycILeketJdP2EBi49QXkRM/wyKChiku97UzNxEYPaMNhqI/NfBOXlv33Q96A3GE29FDvpLMp5oaWeCeGFo4LUbEsY0Duhnod46ad0nO+QaMe9P0FPg== 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=1sA9ZGGwKCFVa3/DR6CR6X7jz2TH0pu4avIrpxeaQ+U=; b=NL4KMSl8o1A2OcMzEKlRHwSd11bKtRQnXQKHMTEKhL/itMgJAQJVlAmjS9I6zZuzE/rLYaGtfwpf1EwUHcJbYroXG3fWJlLQfzEdbA9XZ7dl5l9+1O5GnODiwWGyWi7q+eXB3TqRiMx3+JGwuv/c/08Wsc1kE+tLfQbBCytqEpjtTt+qRAQK7jQwMKQUY8z1IoQs9VV6KMhDWK4qKkdyroVxbdRiIP6Gr8pVleRI8J0cMRsEsz4CpmIZBKjT80bX77ebuh2D04vzkqiiBkHBpKBRyg9qYSx2F8KtqNRWgU5VeV/6ZV+uDu2EkF1ZJ6BQh3L4HZdYTfJ5aUQHY1f/KA== 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=1sA9ZGGwKCFVa3/DR6CR6X7jz2TH0pu4avIrpxeaQ+U=; b=VYLo6CECcQITJTotF/xsVEFajkV1DBcCoae8tEgpnI5TG4qfWMq8ay+6N9+7rYpSWoVG2Ud6iiNGU4GJoCEBOxzfV7s2ocPlOOUwRKyr8HxZ9cnfLB2N1esJXqTBc7KcJHQVdtLwNFqfgm48WvRoQA9y5svcNyzjU1aKF7vLI2VIzOISdDb1OH5LvBLAOG4grmtma1ApRSjqsNG1x/ZLRSNtYAjhBlIRN5pmI8scxik9eUqWu4VtivzHNlaE5hIk1rt9tjDlM1qCNS0cr0iQY9vCz0lAwfK952r2PKISxH+gmoorL5RDUsQWKIxeK1gdgJkkRLLZVoy+0NvqgoFQrQ== 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 AM8PR04MB7265.eurprd04.prod.outlook.com (2603:10a6:20b:1d8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.21; Sat, 16 Nov 2024 14:41:08 +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.8158.017; Sat, 16 Nov 2024 14:41:08 +0000 From: Frank Li Date: Sat, 16 Nov 2024 09:40:42 -0500 Subject: [PATCH v8 2/6] 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: <20241116-ep-msi-v8-2-6f1f68ffd1bb@nxp.com> References: <20241116-ep-msi-v8-0-6f1f68ffd1bb@nxp.com> In-Reply-To: <20241116-ep-msi-v8-0-6f1f68ffd1bb@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=1731768057; l=6297; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=/7Pai0goKHvPIK+tBY0qEDaD68qr8tke0aMwrO4/bPg=; b=aolckxJBE7NIPP15dDaja5aOivqFX0rMvEJ8oN4Hfa2HiMT43Xbadu4x5MwNsXYQhI7hH5Bcz FOhmx3bYlXpCsw5gwKb0AWcFpsBYTJIddaRZFz3EOrNtMS612sVDdNt X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0210.namprd13.prod.outlook.com (2603:10b6:a03:2c3::35) 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_|AM8PR04MB7265:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ad3b6f4-3474-4720-7133-08dd064cb565 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|7416014|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?VllOTGtORy9PdFpDTmdCTXQrTEZyQ04wRWlJQjIxZW96OGJoNG5Id21aTThP?= =?utf-8?B?TU5mb1ZnOWNycTNhSDRnU0RWRUIxejBQTVNxTElqL29YbGdwdXBGeEpybTVh?= =?utf-8?B?V1NLYk90eVRDdEhHTjZwQSt4N2RMZEwyY1JNbkxaTjNodWF1a2RwMHI4c2JC?= =?utf-8?B?cXl3NHN0TTVTcnNhMkduVUNrWklrK2dNM3kzd0I0bEZTMFFIME1HWEpna1Ni?= =?utf-8?B?bDBvcVBnUjI2clBzZ1dzeHI2TkwraXRySGlJdWxjbVV2OXk3VVdtaUx1WFlQ?= =?utf-8?B?Mk9NNHd3dWFWeHpLZDR4am5admtJOWxEajRiUVZVbFlDdkFDVS9NUlh5L2hJ?= =?utf-8?B?RmppdGlhOW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?utf-8?B?bUVIeWhFUHNoakMzRlkvc1FDWkczam12eGN2Ym5sQzJUMHNRb0NuZ3Z2NEVH?= =?utf-8?B?a3h6NWNyblEwR0JoOFdxM2VRaUR3OVpFeDBRZlNpK01VWTlQdzlLb2IwM2Fh?= =?utf-8?B?d3A5bU5OVFZ6UWJKQkRyZHk5Q2JCdnRiUlFBdVhiZ0hsMytYSGhZZGRwZEhN?= =?utf-8?B?QTZ3eVo1dFBQNW5KbW1LTTJPWlRkMHBZQnJkL3Q1TlBuYmZuK0x0MldLWTlX?= =?utf-8?B?OURMQ1Z0Tk1QSHErUmwrc2NqekNQNzdaUjF5NlhyNGhvbjErREFLUU9FLzFn?= =?utf-8?B?UjcrK2JZVzZzbWZPWU5UcUVqMUEyZ3hkakdOcXl0UHNFQTY0VHRPQmd3eEFT?= =?utf-8?B?bGZpZFQ4TXZPUFU4QmZnbW9KZng3cFlVR2VjcXpOelNqS2xjTVpEZ3JMK3hG?= =?utf-8?B?QVlNUDhzV0NFbWNaczJ1QlNSN0htRllOeTVHVnkrdGVEZTZWZ2FwanAydm1v?= =?utf-8?B?d3VqOHJPanNyN1VqL1NiUzlBZHpLUnZBN0J2MFhhNlhJblQ4WUVsaTEvRFFx?= =?utf-8?Q?Z8NyQjeqZOYXb6x4bXUv4os5RFFJXj6S1/8/s=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)(52116014)(7416014)(376014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Y1g5ZktKRVVxaDB5Y01VeW1xOHR4d2podXBjT3BvVnhHRllnMlBJdTlQejBp?= =?utf-8?B?TG9FdXMzRU5wVkhnU0lBZnlqbGhOSTh6cWhmSW1HcXg0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DZsdk5ubDhzOUhCZjREZW9rcDR3Z1VSeDJCZjhU?= =?utf-8?B?NHBFS3RXYnVlVHE0d0NGUzhBUGp6cGZ1YTh3Slc0dVI5U05SbVFMUWFyRXVY?= =?utf-8?B?LzZRZ3Y1R3liU2pDYS9iT0xQU20xaWVPZVZ0Yk5tdmFpQWxQVEVUai9DaG12?= =?utf-8?B?SSt0T1dpM3BrZVJSUVgzK1NqbkNhQTgrNzBHSlAyUWdVVDZzZjdIU3dJMmYy?= =?utf-8?Q?flyM=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2ad3b6f4-3474-4720-7133-08dd064cb565 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2024 14:41:08.7943 (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: YMeSCH2ur+wcKpQgYegsA4kG8+vP5dDwZLlh5/jrzByZ3/iv1kiKQSVlaGRac9ZXA0tYhq5hNDj5w7jFkKdrdA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7265 Doorbell feature is implemented by mapping the EP's MSI interrupt controller message address to a dedicated BAR in the EPC core. It is the responsibility of the EPF driver to pass the actual message data to be written by the host to the doorbell BAR region through its own logic. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- change from v5 to v8 -none Change from v4 to v5 - Remove request_irq() in pci_epc_alloc_doorbell() and leave to EP function driver, so ep function driver can register differece call back function for difference doorbell events and set irq affinity to differece CPU core. - Improve error message when MSI allocate failure. Change from v3 to v4 - msi change to use msi_get_virq() avoid use msi_for_each_desc(). - add new struct for pci_epf_doorbell_msg to msi msg,virq and irq name. - move mutex lock to epc function - initialize variable at declear place. - passdown epf to epc*() function to simplify code. --- drivers/pci/endpoint/Makefile | 2 +- drivers/pci/endpoint/pci-ep-msi.c | 99 +++++++++++++++++++++++++++++++++++= ++++ include/linux/pci-ep-msi.h | 15 ++++++ include/linux/pci-epf.h | 16 +++++++ 4 files changed, 131 insertions(+), 1 deletion(-) diff --git a/drivers/pci/endpoint/Makefile b/drivers/pci/endpoint/Makefile index 95b2fe47e3b06..a1ccce440c2c5 100644 --- a/drivers/pci/endpoint/Makefile +++ b/drivers/pci/endpoint/Makefile @@ -5,4 +5,4 @@ =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 Fri Nov 22 15:45:41 2024 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013052.outbound.protection.outlook.com [52.101.67.52]) (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 C418985270; Sat, 16 Nov 2024 14:41:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768075; cv=fail; b=JgLT0m4SANv6kJWtMbF0wEo0DVrS3jOfO8sliy1mDxCjuTRgbb8bs0f2oVapP4aEBXH2rEhpGOAyNPB5oMC8COxF+19uGhaLfY0zGDDaRWdzsqbVHUzb6AfN2HxP9NuMXN2em+965v8q9fUC1XiNqdc+kq/NN1N2S6/WAh0Tz1U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768075; c=relaxed/simple; bh=ALBAmWL9QxkgiZp6flstYazhrERZ/ebCU5ovpzJ3ESM=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=dktGos92A77wETDufjEy6XskzYQehJgo6zFnb2/N9LJJb9lKk4bt/lthnao+htbRSQ4ZA5iHA901zsYcbUIaLBWA+MZwy8ehs9+nYQZXf53Xc1bISqxyvUEo8YT5CVcAom4vGLhA/Bxyes1YWgp/+RGnGkzlcu/fHpuAhzJSZGk= 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=GT4aJ7Zj; arc=fail smtp.client-ip=52.101.67.52 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="GT4aJ7Zj" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Lt6Kd3TCWAxZ7fa6SKW3oP2rXFY42zpkGwnlXRIredkQwyZSFep+IAd5cjgS+TKToKE06XVxvNqY4mg+bqyneMEkHqh+ysuy67yjs86Vh8JAohpolGNtvRJRPWTyXOAkwAYzeIf+0uSm0Sf76ZQZWJAGzVl+ONUUWM/1DB9hoP6xLJz3+jAosmGk31N0+vtey7Jg1qQ2y5cTpqbptc6uJU931r7i9KE53gNwjHKqubCk7Q90PPzvK7ZeTYB8KRSn8wznLcjO5iosEe8eotPCu45cq/ieGmIfV8hk3Z4cxBC6N5kamLyVyFvttSzjnF5FlTw+7vw5uxhju/EQgs/q0g== 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=MY5/Xe0JHtvYAV4/rZwMg3zPMgkyu1iopPbYp02fQO4=; b=tTL44kJ4POM5JNokvJfO7jRYotlEKAoFxAvAqjzj36SyLzr/9ULqfZAu1hfIA9TqGz2MLYYmcynuFfxk2iRbx/WC1crRYelvtXHt1JdoxFItYsGpPKzuC/4dhhGpy+Ud+cyP2DfjmfbqCQuZSHbp7nWlHm7Ow6hlB9lC+kpzyGt8PCKhluFC4Y7VrRWUAaLu75XRZSmj58ngK+LzfXKv/RTtYYdAFFm3tH4PLdNzFGKvFYTzbUht8ZgbrfXaxjKv3sQBzSNRV/AQ4Nd7wKF+BNKka9i/iyjIf/aXaOvcx+Ig13OeUu4cysduSRGZ1bYl9OXo2UjWWXOqHncJMulhaQ== 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=MY5/Xe0JHtvYAV4/rZwMg3zPMgkyu1iopPbYp02fQO4=; b=GT4aJ7ZjVt7VuNYzLZ1Q2yuOBd477oXfQY1XItrIoPO7K9jW9ggWwRa1n/k0QMjZVieX2VMfXRJnD3qTQDNmxXz7mv3KvZ2sKsMUhoAPTgeqB2YKOJ7wxfFryXTVQ93oLqiF6ueVfy4mmt4MqqihjE0CLlTnBPJJJsuPUTAR5mxUAf0GF0OKUoIBvTNpkFPmJEtccRMGMNymg+RSLGi8vuIEQTLuYLxI3oZPEjtZy116FNwEPkZ743TFr7rcpjWRatk35EK+JnuDdC7C1pWXQNLIs1ttSVUskWFNXSQ6ud5cc2utBoY5OEex3U1hCX2G5pnkutwxHtHE88kLWqSe2A== 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 AM8PR04MB7265.eurprd04.prod.outlook.com (2603:10a6:20b:1d8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.21; Sat, 16 Nov 2024 14:41:12 +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.8158.017; Sat, 16 Nov 2024 14:41:12 +0000 From: Frank Li Date: Sat, 16 Nov 2024 09:40:43 -0500 Subject: [PATCH v8 3/6] PCI: endpoint: Add pci_epf_align_addr() helper for address alignment Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241116-ep-msi-v8-3-6f1f68ffd1bb@nxp.com> References: <20241116-ep-msi-v8-0-6f1f68ffd1bb@nxp.com> In-Reply-To: <20241116-ep-msi-v8-0-6f1f68ffd1bb@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=1731768057; l=3556; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=ALBAmWL9QxkgiZp6flstYazhrERZ/ebCU5ovpzJ3ESM=; b=3llnIb+dDZT9nhTeO3V4fobFNL3Innm/Y9a784osQBC92UaQLwFT+sfqe/wq9QXW9m6CdK/yZ P9w6p3MbsNdBi3w4NL4lPEtLdmjpwEa3OzaDBship1VdShJ6XCXIBte X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0210.namprd13.prod.outlook.com (2603:10b6:a03:2c3::35) 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_|AM8PR04MB7265:EE_ X-MS-Office365-Filtering-Correlation-Id: 01f8ab64-7d1b-4892-4844-08dd064cb7b2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|7416014|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?d0ZsR3FoY3ZiWGg4QjB0T0NkNGZiT1BOQm53VXZlbGxtbFowREVzUjJrdVpK?= =?utf-8?B?L0NFazk0NGZVbjJMV1YwSmV3ODNFVmVzc2VtM1Y5cTdIZTE0RHJXSXFLMEVD?= =?utf-8?B?MEwxYTZVd2VZbkd1MVNmai9uWHB3OFc0UFAwb3dBQkJYYXFGdXkyeEtvbU9G?= =?utf-8?B?eXR3c1lGZ2o4NTFtQ1cvV3dEK1Q1YlRGTm40TUtvdU00QUFoWldiSUVxN2RJ?= =?utf-8?B?U1NjOTJ0RW5Hc0s5MkRiak9zVE54YlQyY2krVjdhSjk4QUpmMnl3d25YTzRU?= =?utf-8?B?WVNRUFlRT2RON0QzN1BxdFdpcEV3S0pvdGpyaVRkV0RwaWZLekVjWnFUYnph?= =?utf-8?B?QjM4TzdybHp5NEVoTzRTN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xUYXNZRUdvVHN2a3Byc3dDMk5kalI5VUZvNkIzaXArUkFodnlwRnVwbUJV?= =?utf-8?B?WFlSVEptOEExYnlTMll0WkZvaTVoVmMzbHVlTWdJZlZZRGYvSUt4MGFqRU00?= =?utf-8?B?d05Ma1hkWDBWSnhVOXJ3SlViZEpVYTJjb2lyS0o0VEl6NUJiRVd3K25lNERH?= =?utf-8?B?dzlNMVNsL1ByeUlzKzFKN25PTDFnZk8wVlBEN1BTTnZqbWRtZGNPRHVGRS9X?= =?utf-8?B?ZmFiTWZZQ2F2K040MVlpMlRwQ2grMTd0UG5lZ1NWS0MzSk1UTDZ5bkRYQTRX?= =?utf-8?B?TnJTVGhtZ3VyZEZyb0hMRDV3cXBlWXpVZEpFTmk2Q3o2Q3I5OTVLTnFFTW9K?= =?utf-8?B?M3l0RG0vaFVDZXFOK0dVR3I1S2tDemV1YUkzL25PdU9VSkhQYnlUY0k5UHRj?= =?utf-8?B?OFg0UEFvTXM0MFJpNk1hZ0lpVkRKZzhOVmlMK3I4LzJMUHR6L1JsQ3BmR0hz?= =?utf-8?B?UzY2QWpMaytud0NKQ0ViMzg1aExtUnNseHFoaTZocGJOM0NzaVRSbVRYUzBB?= =?utf-8?Q?4/aSmnddmikCPsxk0oqBPQqoGI3lGXRFxkZ6c=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)(52116014)(7416014)(376014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?YnJKK0ZBOFRISTF4VGlnMEkwYy9peFFhSWJ5dnNBVGV0em9hWU5IUkREbHI3?= =?utf-8?B?SHlUbnQ3a0FYZFJTNTJkZmcreW80Wkw4a0p6THZRUG03R3RkdmlHcnZBYU1z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QXY1N0FGUXdTU2cvazZGSkg0?= =?utf-8?B?MC9nNStNWjNPZC83bUM5cHF6YUNPZXplTHBxYk5OT1d1bUd2OGFpRXhJN3dx?= =?utf-8?B?bi9CQTV4ZmNsNC9TTDJSRW9tZWlWdnk5SUpDaUppaFFzdFQ2MjFka0RpZk95?= =?utf-8?B?Y0JwR0gwNjB5ZW9xTFNXVEJnZllwaUZJdHBPMUZYRlVueC9jdE9ZdWg4OG9T?= =?utf-8?Q?Fy5I=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 01f8ab64-7d1b-4892-4844-08dd064cb7b2 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2024 14:41:12.6467 (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: jJhWBaPWvJiS1vDuCnL8fuwBUjpBXXys6jI3e9zDknpHKNhHq6vaZs+byhAmT2L69YIoMLlx2WkBkLhCZ/oQ3Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7265 Introduce the helper function pci_epf_align_addr() to adjust addresses according to PCI BAR alignment requirements, converting addresses into base and offset values. Signed-off-by: Frank Li --- change from v7 to v8 - change name to pci_epf_align_inbound_addr() - update comment said only need for memory, which not allocated by pci_epf_alloc_space(). change from v6 to v7 - new patch --- drivers/pci/endpoint/pci-epf-core.c | 45 +++++++++++++++++++++++++++++++++= ++++ include/linux/pci-epf.h | 14 ++++++++++++ 2 files changed, 59 insertions(+) diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci= -epf-core.c index 8fa2797d4169a..4dfc218ebe20b 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -464,6 +464,51 @@ struct pci_epf *pci_epf_create(const char *name) } EXPORT_SYMBOL_GPL(pci_epf_create); =20 +/** + * pci_epf_align_inbound_addr() - Get base address and offset that match b= ar's + * alignment requirement + * @epf: the EPF device + * @addr: the address of the memory + * @bar: the BAR number corresponding to map addr + * @base: return base address, which match BAR's alignment requirement, no= thing + * return if NULL + * @off: return offset, nothing return if NULL + * + * Helper function to convert input 'addr' to base and offset, which match + * BAR's alignment requirement. + * + * The pci_epf_alloc_space() function already accounts for alignment. This= is + * primarily intended for use with other memory regions not allocated by + * pci_epf_alloc_space(), such as peripheral register spaces or the trigger + * address for a platform MSI controller. + */ +int pci_epf_align_inbound_addr(struct pci_epf *epf, enum pci_barno bar, + u64 addr, u64 *base, size_t *off) +{ + const struct pci_epc_features *epc_features; + u64 align; + + epc_features =3D pci_epc_get_features(epf->epc, epf->func_no, epf->vfunc_= no); + if (!epc_features) { + dev_err(&epf->dev, "epc_features not implemented\n"); + return -EOPNOTSUPP; + } + + align =3D epc_features->align; + align =3D align ? align : 128; + if (epc_features->bar[bar].type =3D=3D BAR_FIXED) + align =3D max(epc_features->bar[bar].fixed_size, align); + + if (base) + *base =3D round_down(addr, align); + + if (off) + *off =3D addr & (align - 1); + + return 0; +} +EXPORT_SYMBOL_GPL(pci_epf_align_inbound_addr); + static void pci_epf_dev_release(struct device *dev) { struct pci_epf *epf =3D to_pci_epf(dev); diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index 5374e6515ffa0..eff73ccb5e702 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -238,6 +238,20 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t = size, enum pci_barno bar, enum pci_epc_interface_type type); void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno ba= r, enum pci_epc_interface_type type); + +int pci_epf_align_inbound_addr(struct pci_epf *epf, enum pci_barno bar, + u64 addr, u64 *base, size_t *off); +static inline int pci_epf_align_inbound_addr_lo_hi(struct pci_epf *epf, en= um pci_barno bar, + u32 low, u32 high, u64 *base, size_t *off) +{ + u64 addr =3D high; + + addr <<=3D 32; + addr |=3D low; + + return pci_epf_align_inbound_addr(epf, bar, addr, base, off); +} + int pci_epf_bind(struct pci_epf *epf); void pci_epf_unbind(struct pci_epf *epf); int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf); --=20 2.34.1 From nobody Fri Nov 22 15:45:41 2024 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013051.outbound.protection.outlook.com [52.101.67.51]) (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 F36622BB13; Sat, 16 Nov 2024 14:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768081; cv=fail; b=vEXRAKUwSRZVBFFa+jEQzzCJ++RbO01b7D96jFVUwdJAPnhRmxM0hUZYBluriiFZKNikvJt9lvsNYomIJu5qo3mAubP3FuBdeKSvkN7rO5gbYSat+xcEzhjxXzYplD1dbmWCXl1MqTuEkjR2X9mYvZ+8IpYK4AOy6LwAiLJkpd0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768081; c=relaxed/simple; bh=4vKx2rPx2m7XWgRxYUh6kb9XgUf/PMkH85+H1/AB+sM=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=ABO8ulXy/GY94dgUX2E3YbrPKzpGnIKtWyl1JkQYgFwz5VNAO+oraH26Atdw5wSQ4pAsJY76KiMjWCO4rFa5sjCIhl+trNsP+d0Z5oKdUfxISk1rCLgZ70IcHVmOY8QicSMleN9U0YJuPgKnC23PLwkiRL6eDKspB1Cx6/AOIXY= 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=a34Q5pii; arc=fail smtp.client-ip=52.101.67.51 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="a34Q5pii" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AMoY2i0eUKmk54rBAvn91rFyjdWFgnLwbKUXaPfsbtxLVBjPb/AN4i/O/MsT3Hf+hVxw/GXGW/LWNjd+Hf/U89tX+luS9yPNjsNBb9hAHzg+trAFco7r1HpUuK8Pm96C2Fdpz2R0cgdYi4VGRkKk4uV3P08KLMTbm2BPKqSTCadOY2VgNBbKKjVqetbs/xMKpja7D7HV84Z6Nj214SAU8FXXwqm0AF9qWoz5+nAwP1nyac8/pQ/6hbZu7o/3SY8G8xdS8q8gSp22Agy+ZHjoJGc6pq0aViPCmUbioMCGasGZsIssZI+3RJJ6dZaTlr8mneSvViOT8EyE3bgMkFAbxQ== 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=AJ22JWiQxp/Dsr6tuhGS3SeKCcsaE199Pas5L1A5Z/k=; b=gupbtZb4kROgRKjpwTf9q79RnzDbmLSHY9qKpZ1xbIsiC15xBDMoWzvyd1tydJ/A048g1Psp6/TJ7D0gb3xxfLA88BKxLkgUoPQY6VB3Rvq1Jz8evwh6MAG8F1EjVpJyWHsSQ11X46NUrlligCn96VOfcWGdRqqXLderKC4NYXCcqgUagBDBGyz0iBAiPM3YOCrMqWifeYiQAQnL/6kq7pZOuEJ5olqInRjWVrOWcgB1byzGpcHtSxT+vunRMuZ2tEwD+Z+UKb1omx6GsXweNvBKYoqfRC+SMupLwaRamzB79h/fZqiu1OrJKMHuxj+twDC66AACLQW6xumC1pE+uw== 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=AJ22JWiQxp/Dsr6tuhGS3SeKCcsaE199Pas5L1A5Z/k=; b=a34Q5piiA4DrLGgONnQjt7iRkD1fj6vJIDRZqGUODznLa70MPv4MceZpg6/Fwjd7WUpdoi1x1BEHeUF0ZrsQ17/uaesJenu78TiM10iwZw4GzsPr3cRbyI1nT0WT0jhmbvzQzQj6VQ7I4IMw6Biez8RPYgp51Puvbju+f+rSseaqB4yYOHcrMzDHATtMxNPpGa3RQltciSA5OylF2/RW8+8072qXZjBy/lKZb7DcyUabkDHFGiKllfQBwLOC+CPuuRqpjL/HxvJQyWDyqDe6jPUs1kvk5yJ1eM/HlriBo0NEXE+6kKXgOENLGBbd8nVwrtB3Dfmb12ho7ubL/HXd4w== 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 AM8PR04MB7265.eurprd04.prod.outlook.com (2603:10a6:20b:1d8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.21; Sat, 16 Nov 2024 14:41:16 +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.8158.017; Sat, 16 Nov 2024 14:41:16 +0000 From: Frank Li Date: Sat, 16 Nov 2024 09:40:44 -0500 Subject: [PATCH v8 4/6] PCI: endpoint: pci-epf-test: Add doorbell test support Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241116-ep-msi-v8-4-6f1f68ffd1bb@nxp.com> References: <20241116-ep-msi-v8-0-6f1f68ffd1bb@nxp.com> In-Reply-To: <20241116-ep-msi-v8-0-6f1f68ffd1bb@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=1731768057; l=7742; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=4vKx2rPx2m7XWgRxYUh6kb9XgUf/PMkH85+H1/AB+sM=; b=Jy4o0qZTn0v5n8B1dAPRcLp2iYSVwNri5rxx4sVkbNfB4zlzngT9PCf95RinIkM9JM7xNXYyL aw5yWDOuiMxD33SVtRLQj5WhtiCnPevt0aVOW3/zTEOAN211kdT581I X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0210.namprd13.prod.outlook.com (2603:10b6:a03:2c3::35) 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_|AM8PR04MB7265:EE_ X-MS-Office365-Filtering-Correlation-Id: e820607b-6aaf-4abc-14e2-08dd064cb9f7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|7416014|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?YkRKclVsVzl2Z1NHUU91TFgzSm1YWkpVQVN4V3pHd05xVjdyck5WS2QzaFlY?= =?utf-8?B?Q0FIeU1FZEgrTzhnV2JTNXRXaDVQUVM2RHNXS054MC9uR04vRCs5cnRqem9T?= =?utf-8?B?TWFvUWN1MlRQOHR3UFRycGwzVys3RTZRbDFBcEJIc2orakFESlNyb3NWSzRq?= =?utf-8?B?Ulc4K3hBd3ZlSG9KTWRLZ2xIMXJkS0JzbmVaNmQ2cHM4dFdtY2pTRXYvVFVr?= =?utf-8?B?SVEzMnhQRGdSOFJPTnBGTy96aW1hME42b0VIdVo5N3ZxMEFkNFJNMlErSnZy?= =?utf-8?B?Z3k4ZFE5b1NQa1FDZzg4cEpoQ2xrOEJRb3RJMFBPMzhLekZ4SzIwN09NaUMr?= =?utf-8?B?SVM0RElFcjZZZjhyaDBYQktZNDQvd3ZYNk45M1NvUlRZL1ZaKytoNXhMbTc4?= =?utf-8?B?SklFamFhNGJWdlNIUmdpVlY3SkRSVDh5S2Vmd09SV21oRFBsUFZ2RTF5Q0h6?= =?utf-8?B?YWtmUGhzd2R2WEwyeG85cG1WQm0xK2QxbUlWVlV0MnB1d245ZGpPU25ZdHd5?= =?utf-8?B?NU5ZbjJ6R3p2c3IzN1c0d21uSGFGT013ZmJQY3ZKQkZkaFZIRklvR1dtbHdv?= =?utf-8?B?SWkvcEpKS0VTdXYxUE1Sdk5DaURpM01QNFJadndTYlk2VFNjZFlUL0pvc1Bn?= =?utf-8?B?ZE1FRzRsYVhoclc1NWd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dWJiSS9NSWVuclBPRjFONEc1RCtOcEVQNGRoNWtJZ1ZZY21H?= =?utf-8?B?ODk0V09HY2ViMGJmWXVGSDhFMTU3bjF3MGF6Sm5xR1VmbGJqWDhYTXJUUmwy?= =?utf-8?B?bzhrdWkzVjQwZDNqb2x1OFNHcWhqL2hRRGkzY20rNnNISnhwM0pYcTJsaU9l?= =?utf-8?B?cForRGhUMHRUbERlNXF3VzlLK2k5cE9HWDhvZVIyV1Bxb0plUFpwZ2RrMER1?= =?utf-8?Q?FhGt75Z5PaAu8kmAURMN/Ibqwk36oj4Twpgd8=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)(52116014)(7416014)(376014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?OEQ4V2ZxYU9ZUm50alJyUU1leDNDMHFLUGlGUG1IMCtja2VwVERNMmlxa0tR?= =?utf-8?B?VUZMTkhLWVFzOU56S0p5UVkrTDZkSnVxOW02anF0UlVxeE1UWU1EVUVrNlc5?= =?utf-8?B?Nk1FdndFbGdCWnFpbEZOeVZUaWlNY2ZGU3V6OFBxVnBiRStsazZna0NLQmZM?= =?utf-8?B?c2twYXdaUjl0TnlGbE11eUlneUlGZFRrak9OVFRRc1pDM3NTVHFYMVVpVUhB?= =?utf-8?B?djMyZ2RpeVd6SmorSEczVFh3M21NTDZob1Z4cXNIQXdBV2JzT3pGWDVGN3VK?= =?utf-8?B?M2ZHVjBIa2FkWCtOTzdhdmxNbVdRNlpRYzc5TXMxd080VDlXMUhEa1hYTnJl?= =?utf-8?B?UEMvb21hNk5ja1JqK3NYOTRCYjRPcDJqK3QxSWMzNkxrVk1SSnYxbHVnelhM?= =?utf-8?B?MkxMVGdyQ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enant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2024 14:41:16.4653 (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: ybkk0/tJOnwHSzvDL/ZxIUQtgr0dWwXoBt7/0GVZ8QE5iRV0gdN6z7Xnyn8yVpI/sA9KPfru8xJaRGF45OKSvg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7265 Add three registers: doorbell_bar, doorbell_addr, and doorbell_data, along with doorbell_done. Use pci_epf_alloc_doorbell() to allocate a doorbell address space. Enable the Root Complex (RC) side driver to trigger pci-epc-test's doorbell callback handler by writing doorbell_data to the mapped doorbell_bar's address space. Set doorbell_done in the doorbell callback to indicate completion. To avoid broken compatibility, add new command COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. Host side need send COMMAND_ENABLE_DOORBELL to map one bar's inbound address to MSI space. the command COMMAND_DISABLE_DOORBELL to recovery original inbound address mapping. Host side new driver Host side old driver EP: new driver S F EP: old driver F F S: If EP side support MSI, 'pcitest -B' return success. If EP side doesn't support MSI, the same to 'F'. F: 'pcitest -B' return failure, other case as usual. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- Change from v7 to v8 - rename to pci_epf_align_inbound_addr_lo_hi() Change from v6 to v7 - use help function pci_epf_align_addr_lo_hi() Change from v5 to v6 - rename doorbell_addr to doorbell_offset Chagne from v4 to v5 - Add doorbell free at unbind function. - Move msi irq handler to here to more complex user case, such as differece doorbell can use difference handler function. - Add Niklas's code to handle fixed bar's case. If need add your signed-off tag or co-developer tag, please let me know. change from v3 to v4 - remove revid requirement - Add command COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. - call pci_epc_set_bar() to map inbound address to MSI space only at COMMAND_ENABLE_DOORBELL. --- drivers/pci/endpoint/functions/pci-epf-test.c | 117 ++++++++++++++++++++++= ++++ 1 file changed, 117 insertions(+) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/en= dpoint/functions/pci-epf-test.c index ef6677f34116e..410b2f4bb7ce7 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_offset; + u32 doorbell_data; } __packed; =20 static struct pci_epf_header test_header =3D { @@ -642,6 +654,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; + size_t offset; + int ret; + + 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; + ret =3D pci_epf_align_inbound_addr_lo_hi(epf, bar, msg->address_lo, msg->= address_hi, + &db_bar.phys_addr, &offset); + + if (ret) { + reg->status |=3D STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + reg->doorbell_offset =3D offset; + + 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; + else + reg->status |=3D STATUS_DOORBELL_ENABLE_FAIL; +} + +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; @@ -688,6 +757,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; @@ -822,6 +899,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, @@ -921,12 +1010,34 @@ 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; + 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; + } + + 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_sync(&epf_test->cmd_handler); @@ -934,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 Fri Nov 22 15:45:41 2024 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013010.outbound.protection.outlook.com [52.101.67.10]) (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 BDEDA38F9C; Sat, 16 Nov 2024 14:41:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.10 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768084; cv=fail; b=LMxZ32HTKczWglYf6SXVJspR2aUW6JPvsbPZc17r02U46Fyk6xQmyZO5ne150b+ERHhJwi2Lb269dS4/kd8OXEF+4C6HtxqCMcT7IeGruVHhlpT3xSmJSw90I6l8K4RaOLtV7/td1ytYDsw1NoPRJ8TbTaBt8LyorBtuTWF1kjs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768084; c=relaxed/simple; bh=bfBlohtvx2bmitM09sd2P0/1msiF1RQlPsCuEI4gWds=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=AxXDWYtaPhDU91L5uREdnVOzZbiA5ViiyjGOZ1d6mI17PssoD7ehhzxB9VDAR16N4HNwf31Z5o8Tg4LQKJseqlQ6LJyjgRSqEy0Q2roMSzNKUegYQz2GPfgx+y6RgqVNtcvX8EuEuj5BJuv2qbGuj8+KqP+cK8TFsFm0khzPmSM= 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=Em70wJrX; arc=fail smtp.client-ip=52.101.67.10 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="Em70wJrX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yUPAes3xkdt3aj0dclhi2rtwtKmr43o/MdQwFFgdJAMDIsm8HNYZjPRzP9PpyEgxR9BA5YNennzwSrxkngrW8bJFiMszdLUh/jvyPILoSYe1bYfKlDHKEKRX3XN5b+OOghV6t41xaI6Ni9XC6WQGsC/6E5qjHMF5rt2rE3/cyFX5VfgCmD3K02sa00Ri+unrMapRXXSDjCAszjZlm+QGWBWMFUu6fnFhHNk/8ICjoZAbRcKVGoUf4SArXdkUHVApneDntYQxA1y9y0NtZRazBJuJsrThaVpTQN/HFZn5YSCqpLBZg8WiFhJnuNG1NxZH+sl0HcNMewAeszwBk0Aj8g== 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=sPLSAjBxVhmW/iYWYZ4v4ELai9IvZTkeFFwJE94I+Ww=; b=Dk0GX3ypQa9NdnxPOkwHb0bqBnoXJwkeEn8zvOfmzOrafBrxK+hG4WDI+Cb9VIDlBmsnCotxiPGHtXEJxtPJqdDcglHiGfudiWcLcJw90dybRJ18KH1/k3PzQkBR+dkt8oqbJ4WjnI/7HqsogKYBsGBPI1pPjuy7SMxclmtTUguEEw0mEjcQCD60uUkoUpAaGpeTxG5Umj71/zeAS8AqVwD7SZt5L2sMh+UXszLgkrR14krWO0Y2eRhAQKJDgCT474ET2870hCsUIuFJTu5qxCzW4ZCTW/4kszBvG/qA9kn/KOx9IUvSSEjEE7RQ9sfW6fmgYdk+JDQQR6YWmD7qrg== 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=sPLSAjBxVhmW/iYWYZ4v4ELai9IvZTkeFFwJE94I+Ww=; b=Em70wJrXGL49ancuIJAdvqVAMXtEX1nyZgS5QiRTXGvakNekPe3n39GCVpLvRnCyIO5tfS1/Bqy8imNQCRvUIIEuR8YVBzNhyQTqv13lXiiNDSPkAh4cySjpDLmqKbe25mY5aqIA76xkjIm6AWCI2Gt/vb+nKq7zic/lbrMiUH5uSHvVFeZFBhWorgtHPqPZJTI0bB2RKZpP5gVmLTQoOLx62dMSy2DtwszJC7D1e3zvc3kpTR2oPwCWSbFW+FadZSwkl2l/2fBAeWj1tCSotUqG8WZbVdbG8s/4v5ybjrjN207AbswJbma+y2kmvr7KsulEDBbOBm8MhISUuWxPZA== 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 AM8PR04MB7265.eurprd04.prod.outlook.com (2603:10a6:20b:1d8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.21; Sat, 16 Nov 2024 14:41:20 +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.8158.017; Sat, 16 Nov 2024 14:41:20 +0000 From: Frank Li Date: Sat, 16 Nov 2024 09:40:45 -0500 Subject: [PATCH v8 5/6] misc: pci_endpoint_test: Add doorbell test case Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241116-ep-msi-v8-5-6f1f68ffd1bb@nxp.com> References: <20241116-ep-msi-v8-0-6f1f68ffd1bb@nxp.com> In-Reply-To: <20241116-ep-msi-v8-0-6f1f68ffd1bb@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=1731768057; l=5527; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=bfBlohtvx2bmitM09sd2P0/1msiF1RQlPsCuEI4gWds=; b=R7yeWlooL09qMBHQ6B5jA/netTygU+2xCXeQeYPhP+4oTtMk6hlya2JAMPdOt0Vf3T3S8Yn25 btDmwrEgvaHC4gfzw8jCL01LTijIf38ZbKNdoh06soCMTO8Oh6eK/0I X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0210.namprd13.prod.outlook.com (2603:10b6:a03:2c3::35) 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_|AM8PR04MB7265:EE_ X-MS-Office365-Filtering-Correlation-Id: fa82eb39-b14d-47bf-2fd5-08dd064cbc42 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|7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1h3YUhzYTBB?= =?utf-8?B?WDluNnZWbjd4U3pydXlGR1lXTGhDQWYrellYcittUWoxL0tWbzNrYVU3d2k0?= =?utf-8?Q?K76gxy3g0tqpNqOET5YnKgw30U/nHtYmZIKEw=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)(52116014)(7416014)(376014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?OXlLazA5cHdKSzJuVGtCU3Z0Skc2YlBRanNKK1NQaytGdzAxS2kxSzdBelBW?= =?utf-8?B?UVRsSkR5SDRWS0tjVWlnOXF1eGF1bUpmT04wWXJGNzR0aytXSWx4WEcwZmZV?= =?utf-8?B?N2ZpNG52dXl1Z3JiWEc1c0hnTHpPS1NoRmM2Tktlc0hCRDYxUW5abWdxbXp6?= =?utf-8?B?YWdyQTVyelI5czhlZFdwYkJnWC9CV2pYMFpLcXdMUVNIcDNHMU9sQUVDTU9j?= =?utf-8?B?VnQxdFBrWWRiMVFkMUNBSGIwVnJpQlN1aTc0NDlzem1wUnpzcFpQRnRvTXlp?= =?utf-8?B?WFU4NFlUUE51MDlBZURnU3Z3Z0FURWQyaHlMTXRtRWk3OXBRbEl2UmZ0bnZZ?= =?utf-8?B?MkVuUktSU3pFMjlPaGVWeTJpUzBDdCsyNmJ5Yk80SnVUdVA0SFVDTFlTQUFM?= =?utf-8?B?WjNoZmRNQzd3M1lka2pBaHZZcWF5VDR2c1NKelhtWTd0MjR6VzdGcVdOOFl5?= =?utf-8?B?a2lYNVFHbFQwOEQzUEY4U1JKU2wyTWdld1k1YVh6VENVL21BRTBmZHMvZzg1?= =?utf-8?B?a1NrOE9OV09QWlBiRDVpcHBrMFMzdEwxcVVBcnpMWTZB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0TTYzbERWMU1nQ2kyaEl1QVFWb0dsVExiMG5PTzFQ?= =?utf-8?B?Vkt2YmFJUnRmdnNiZFNmT1NVdTl3NG81WlJpNkhaWTg2VXd2Z3ZvSm9yNmZ5?= =?utf-8?B?MVNRaDhRa3cySzlGZWVmb3QvY3Q3bk9PS1RIczVleWF5ejhISUY5WDFRbmlN?= =?utf-8?B?a3h5cWxKWTZJSGZ2VUhVQTJONUdId2REQ0FhUFNCR1RJSjFLOW4zZHJaZXVY?= =?utf-8?B?NFVnRkl6T0h5YXJ3aUtVZ0VIK2Q1Z0lHSVFHc28ybWVWK1VjbE5jT3NuNVNh?= =?utf-8?B?aDhIYWt2TTBTdi9KWm1LODc5ZlJVUmJFS0RiUDJPZ3lqWmRyek80bmlraUU0?= =?utf-8?B?eVhhdFVFeUs0N250RFJjSy84MU0rajBXTVFtMWhIdmFJbGFjUHdtaUpBbjBS?= =?utf-8?B?am5vWXVtNTYwbHVVYWZCTTg4eit4TnNydkhPNGw2SmUwT1hFemNvb1p6Rldw?= =?utf-8?B?RDZybjNOQXFBQW4xTWtHQytVSXFTQzIxZEpWM3pDWlc2YlNueFExVzZvdkUy?= =?utf-8?B?RC9OSXlSbkN2RU1lb1EzRGI4bnNiN3ByTGhvRFBmTzMxamNpdmdFR1NRYm1w?= =?utf-8?B?TzNjcGZYZHhKb1FWUGxCQXgzVERFNjQ2YmhocTR3UXFYUk9vbHVZM0xQNmI5?= =?utf-8?Q?p7KQ=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fa82eb39-b14d-47bf-2fd5-08dd064cbc42 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2024 14:41:20.2970 (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: Ty/GE/nqDJ8h0fSl6AgUCQ7yhYY2iGRdWNSTO0FHJWo25HH0FlDwnJ3deqDM93ckkhreJeVGq8XhV1FEDcVZRw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7265 Add three registers: PCIE_ENDPOINT_TEST_DB_BAR, PCIE_ENDPOINT_TEST_DB_ADDR, and PCIE_ENDPOINT_TEST_DB_DATA. Trigger the doorbell by writing data from PCI_ENDPOINT_TEST_DB_DATA to the address provided by PCI_ENDPOINT_TEST_DB_OFFSET and wait for endpoint feedback. Add two command to COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL to enable EP side's doorbell support and avoid compatible problem. Host side new driver Host side old driver EP: new driver S F EP: old driver F F S: If EP side support MSI, 'pcitest -B' return success. If EP side doesn't support MSI, the same to 'F'. F: 'pcitest -B' return failure, other case as usual. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- Change form v6 to v8 - none Change from v5 to v6 - %s/PCI_ENDPOINT_TEST_DB_ADDR/PCI_ENDPOINT_TEST_DB_OFFSET/g Change from v4 to v5 - remove unused varible - add irq_type at pci_endpoint_test_doorbell(); change from v3 to v4 - Add COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. - Remove new DID requirement. --- drivers/misc/pci_endpoint_test.c | 71 ++++++++++++++++++++++++++++++++++++= ++++ include/uapi/linux/pcitest.h | 1 + 2 files changed, 72 insertions(+) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_t= est.c index 3aaaf47fa4ee2..dc766055aa594 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -42,6 +42,8 @@ #define COMMAND_READ BIT(3) #define COMMAND_WRITE BIT(4) #define COMMAND_COPY BIT(5) +#define COMMAND_ENABLE_DOORBELL BIT(6) +#define COMMAND_DISABLE_DOORBELL BIT(7) =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_OFFSET 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_OFFSET); + 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 Fri Nov 22 15:45:41 2024 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013021.outbound.protection.outlook.com [52.101.67.21]) (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 AC85D44C6C; Sat, 16 Nov 2024 14:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.21 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768088; cv=fail; b=vCyU4dUILQXzbCHoTA7zkqtZsOHx89ehMucXYuwY/K3EMcHSllZxk1lH+EuQwsLGKdU6dQfU402Dd9JcULii1hwGr6j0ypSd21y+khLzz8cZyhVsPailP60APskuIVlZneO0hu8XZ5vfM2dfhJ3VA7Gnx+cQ45jb9HVZPAQKn5g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768088; c=relaxed/simple; bh=PMPeULWcd9APEf5NgSWWzp7T5Vx20NKWDiBCjH7nCZ0=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=rVswaRo56SJbG5cV4lKEwZUEQvncUFDeO4Jxn7j99SpxMEdEpNbZIesiRNLbEQjkLAxDHSriyYhxeoiHLXIUzVA+YufDM2HKNVzsIOFv9y9U2qiedvzfJovScXyTnURH7CB195WFe4BK4pZpnA48ZmrDTt7qVJ90QC0ZX2IaZ74= 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=n0nd+Anm; arc=fail smtp.client-ip=52.101.67.21 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="n0nd+Anm" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=okmLCxSWKzH8j6tXc4JjsdkY4D2xEN1qPAMFnahjRyfjjq9R1IoRxyXxe8NO683tpygD8fr5XnEUf2L78vf2vNC4v2DbTr4Cj6TzweF6cya+jF8W1KjyRyZvSDGueZ2N+ZPnXkz65KrEPJAd6ffA5VxQzBosl85B9VnZxFiVpPRLUPUSwbf9NkAc3MRrYqfPoBRKP02PN/y3pzEhdAAW7IGyudwlwYW6IEgk10hvgli1j4EaGdxIfNJC4EntOLAWAVBiDNNH2e6frTSa/Qj11edQUlwbF7CWwD8dV5nxwEDFHzPTv06ldrzoAD7i0DPFpOWSa4RV62kXl4B+bQdsag== 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=uwKvm2PFG7IelxAqz673F2KybERhxfLWfXM1E5u8duU=; b=WyRVkUZ2VV2axrfoEnddbli0XSQIrsvFLA1yiLPyxjC3mkyv4g3ulVraj7ZPGGkeZcCb/8iglwwtI0sOatD96VpuSacemWx4s4oh0VQJAoPWdXvLbttprD2rL51wucUyPpy/MdJDXhtA8pOdNU1bD6WSHKYi2wrEbth7L453ormnaXHS8EpCr8WOsge9i+u5jAEJ1bBw6mG4sU9hH7Kbt/F3ymTdF+PvicYnXmzFyzZ6CC3WlzwCGLvxzn//rQJCphOYpP6LKNzbhITrwjSCCgjHrP/f8zpdpVgZlQDgjdiyd6Yx/0CzDHoM905yvkADGRB7ZsDY8W3grBujjVwQSw== 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=uwKvm2PFG7IelxAqz673F2KybERhxfLWfXM1E5u8duU=; b=n0nd+AnmNV4NoF2TeffY6DIcIICa7zUKLfRbvWO7m3T4556v7Vu7DYzk54QgErlD/E9tsq04VsCOs2xyhH+Aezm3ZK2WHH435uXnkq0IwyyUtSP8NVN6X/jtHlh3ZDBVZicpDjQBeF1sFAgqYO6J9hoD5GMBVeHrzX5LrDUtUk3ONEk26W+KXwySHyvEJ4k9n/YRHw9TmWpqt00v1/ouktoxetEtxqEQNbdubVjv76WU2yMmKRPiskKtCk+O6jvrtI+K0YFuouwhFudZTZVP/pYwLpvCMQ7NKpI/WKdAkbtMfgem3O3PWiYx/iz+x3pSC9/jRzRsqGp+7+K++/XKtg== 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 AM8PR04MB7265.eurprd04.prod.outlook.com (2603:10a6:20b:1d8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.21; Sat, 16 Nov 2024 14:41:24 +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.8158.017; Sat, 16 Nov 2024 14:41:24 +0000 From: Frank Li Date: Sat, 16 Nov 2024 09:40:46 -0500 Subject: [PATCH v8 6/6] tools: PCI: Add 'B' option for test doorbell Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241116-ep-msi-v8-6-6f1f68ffd1bb@nxp.com> References: <20241116-ep-msi-v8-0-6f1f68ffd1bb@nxp.com> In-Reply-To: <20241116-ep-msi-v8-0-6f1f68ffd1bb@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=1731768057; l=1850; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=PMPeULWcd9APEf5NgSWWzp7T5Vx20NKWDiBCjH7nCZ0=; b=SoKGk63GaV3YU7XiowdjYlWsuvNkLChxn7Ujnh30C8YKXF7nI7eRONMoL0yKyljgwCpeCUpOw yZegV3FcFcDAFCoLusTbNUlZtnKt+uzTUf1Mz0hvgLd7K5cj4ajccFx X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0210.namprd13.prod.outlook.com (2603:10b6:a03:2c3::35) 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_|AM8PR04MB7265:EE_ X-MS-Office365-Filtering-Correlation-Id: d54d38f2-020f-4751-2b97-08dd064cbe86 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|7416014|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?K1RVeXlPUU1FOG9nZGttbUNIeTBsR01qVmwxOFhuNyt3T0lIRGxvZTlmaUho?= =?utf-8?B?eU5BV0RjVWdZTUVZT2x0aHNSZlhybzAwVG9wMm1yNGgzTUZML0lrUDUxLzBN?= =?utf-8?B?WXdTYjhQSzBJT1dZem9lS29nanpxRUs4cHAvK1BZN0d0ek9Id3dPayt0aFBL?= =?utf-8?B?VHR1MkZlY0l1QWU4clBxdEtKYlNPeWEybGJRWFkxNnJsYnc5dmpEVGRCY2RR?= =?utf-8?B?dVhwT3E3SkprS0E3ZmY5RHVybkI5eU1DdGZCc29wa0szWndyWlBCeHBJMnlz?= =?utf-8?B?Wk5Xd2J3Tk9TdERybE9VcTFSd2ZLaVU0UXNRV204TU1odDBuNERpNk5NUCs3?= =?utf-8?B?d3k2M1NUSFFMellKTVNLVjBCWEVZOUdYWnJXUDN3TUJZbWJNUUNnOC8vU1lN?= =?utf-8?B?MDNYR29pWGJndTNqUmFmMWlmQ0YrQm85QjQyVVdpNUlzM3NDbld2QnNBMUxj?= =?utf-8?B?dlNoc1AzWGZ3Q1kwVWNKTnZYRndyWlN6T05wYzJKVkxTcGo4MGEwWkhZaTZX?= =?utf-8?B?Lzk5TkVMQlRyNEhzWXBIN1pZVDM0QThoVHArLzJQaGF0WGNkVmltcjJVamtL?= =?utf-8?B?eHQzbDlTenJxVnI1WEhvcjhOamYyNk9rVS9wWFRVcVhkRXBEQ0lLaHlYdWhU?= =?utf-8?B?QzJpRTdhT1NMTzUyLy85T01Lak00ZnNmbCt3UHh1OVlFR2NGZFJUdWR2alFv?= =?utf-8?B?UEJVSkkxRUpjckNsclJV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ZWHZ5VmVpQk05K255MlJMbnFveElweTZ3SmlmRW1sb2g0L1gr?= =?utf-8?B?cWVhS0dmdmN5RVY5RENjK0R6a0VDSDJBMG1vZ1ZKY2YzeU5kc1EyY0pPUUJu?= =?utf-8?B?eFBHcDN6YUMzQldnOVhBYXF6elh6M1EwNTdjVkJHS1RSSk1JQnU4SExvaHBI?= =?utf-8?Q?Z8FHrUdPogZP8rIlg2QUG/H1QusQPJyz6UXc4=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)(52116014)(7416014)(376014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?ZjNaRkZBVEhWMWJWazl4S3JtMCthTmNjWjBBQ1E2bVpKc0xjSjBpQlRrVEND?= =?utf-8?B?amhLQUFRVW9OODUxYkI3THFiU1pvVk1pMVhWdjQ3WmM4RHQ4cFVMSk9ycmFv?= =?utf-8?B?YndTbVhwNzlzMGxENVNCUk95U2pHOWNjajdLVTVVeTVna0pEYUhSRTlpVUNi?= =?utf-8?B?ellQYmd6VkdNcmlZNk9aSXBHenBiMjh2WTM0a09MMVZrNFUvZFBlUmtLampZ?= =?utf-8?B?U25GVjQ1YSt4V2lFc25IRjdYR203eCtsWlZOemFwcDltMWZ6enh6bGNYNG5r?= =?utf-8?B?WW8zYXhKMWF0dG9KTkxqNjlJbDFBVWl1NHY2ZDRyZ2xLQWE3Tjd2MTFldHJP?= =?utf-8?B?ekRJUzQzdEMrREYyb281V05DNDkxS0I0dEVRSW5maVVlSTZYR1d1ODA5d2lY?= =?utf-8?B?aFVCdWcybmQ4cis1bWZSMUtxSTF0MGpvMFR2NEo2TVNic3V0S21pQndBTjI0?= =?utf-8?B?Q2ZzeCtPRnZ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ZEUDV2?= =?utf-8?B?R0Z4c1BYY0RZKzB3cVMvTGQrMTlMazZTR2FlQzBmbnJQQ0J3VEdFNS93d3V3?= =?utf-8?B?L1h6L0ZYcFN3QXpvSmUrazl3Zm80Q2pub1RmUFpqayt3d3czcDBucW4wL252?= =?utf-8?B?c3hWRWhWck1XTzdWQ0Npbld3ODI4QmIxN1E1SVZjV0tIaENoblVkdGRDY1RB?= =?utf-8?B?RDEyUk4wemp2NjBrZFdiZTNhLzNuWUJ1dEtmcllCSE5wazBsaWdNRzZUaWhC?= =?utf-8?B?azRINVpMRk5Jc2M2TjFLOGJnUitZM25zRzJ1Rk5jVWZiQ0k0Z3duL0xRWkVp?= =?utf-8?B?NzRNWVhtbzNiQkEwTTRRVzVXQmVPTllVeEczU3VWWmVINTV3SEZRRkdDUHBK?= =?utf-8?B?Yi9vMlk0Z0JXU2krazF1VUFCUzk2a01wdFpNZjdKQjdESytmTVdRcEQ5MXlx?= =?utf-8?B?ZjBXbWhtTkQ0RW9DMFlwMm0zOVA2ZllRZ3BRMTlHZWhEZmdjUUlKejRmK2Z2?= =?utf-8?B?TWp5S0UrK255eFNZU0pVczZkbkxSYW5oZjFMZWUwZ2JibFk2a1QzU3ZNdkpH?= =?utf-8?B?VlI4UUVtemZyUDdRUDgzZmlUT1pmL0pPWThIZlEvU25kUUowdTdTc3Z4ZXFW?= =?utf-8?B?cU9tZGRxZU1SM3diS2VtQWI1RHRwWXZ2UDV2L3NESkhQYnBDWjlzUE55UlQ0?= =?utf-8?B?NmRmclJTOUZNYlNkeWp1UEQvbnFnSjE1RnpIbmxnZkFkZmIyT0xwazZhYkZt?= =?utf-8?Q?HjcY=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d54d38f2-020f-4751-2b97-08dd064cbe86 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2024 14:41:24.1365 (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: 2pigb8NQxYoKCEgvM8rdYRamBcYtymuuZQ6BKIP3N0ojMg3D2FwR9z9GqUo8ZB7suBSzSPLEMbOPLowFZ8X6YQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7265 Add doorbell test support. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- Change from v3 to v8 - 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