From patchwork Tue Dec 3 20:36:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13892930 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2079.outbound.protection.outlook.com [40.107.247.79]) (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 75185205E2E; Tue, 3 Dec 2024 20:37:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.247.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733258239; cv=fail; b=LhGFy0fVwD6O4PA2kyNMP5L9q0gHEXQsagkKmpr5l/YFDC51LtJDePuBQKqtiojzAD6dK9qn05v7IagvnTMzXUCkmS+nsPgh7ZDADup/nvZnBMfNv4ejHNfMk/ZEpCsMbOsnRIqMlwE5O8GwVebBqDdALyfFopESDe43TNkOZGU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733258239; c=relaxed/simple; bh=VIyuF+APlHGxVbHCKBU3zVADRJEOLBTDV24SeUflb/0=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=qYMClfrESxfdwovsr2SKy4jAUgleiB056oyG7Asf2wjPL5hCKmG6T8sHw5MCqq1XeAwS9bHJF8DJkeTRabNsA2R0pqnvkTJBIn8WkeaFy5vVVxAAqnvsbSP53K2Yh9p55WkMvg7X2D34zMMmHmBrjs6Z50WxevbzEuIq/zgBqGE= 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=ZCo3Q+0L; arc=fail smtp.client-ip=40.107.247.79 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="ZCo3Q+0L" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=i3UXpdFTU1xYRecO11m2hg1MU6yaU2iU0pCVmDMm2R+B/j7ozCJFwvhkxhWuZsovFYm9DRJNr9VriEQKFeV+DHM++8ssNmuPpO7LsIaYq+NmC/hf8QtAHEw5sdiRVKqYNCb4H5mvFH6yN1aCbRDXyLhJnV3uQAhcByiiZXHnNzk8rxFDy+k/ZhnMKvJ+E8TnN1uR83RMn0VfMk3P11A81SqHoTVfdNG3Pk4Qn6jhYSWudqCB053lriNO2bbeeuk76B+4nZvR0ze921TAGmfQWYobUM9i+rEPuPPCVWUHgxHcdUsO7rMth/iA/rU8OWZHYH7XZCiFF+tKqz2OP8XMJw== 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=DaAaAgIktJ7JroizMUpVdHODPOvPbmLVhjbqsqOxQ/U=; b=lBjvb3WJ4AZZ86HD97kiyO+l5Gfnv2JyqtBdq3oHXAkMU+lfddzEp1zbSJTUcvMYpLC4QvWQm094ukIr9d6HWtLMo7oBTHO6U3Fsj4GI0Gzy2YoswofhB3GHvmrMnGLzBga+E/m+bL3CazHure992mrKTiv2Zx9iqKAMJjfRgzRKPca7LV9EPSVuh4xBjmaR9HhsTcTJ8rdjEkDnEP6SgGClhh+OeGSkDLDsw6PBtN4+tSJJTjbsfCk4EsFvN1KSnQDephX1wCf0BFHcFoHQfuiCA4Vv2QakMGR20HLeTnm08xy8lN4oOTlZaT9rogL+bb1ImeC5l3LFVTnqvXUToQ== 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=DaAaAgIktJ7JroizMUpVdHODPOvPbmLVhjbqsqOxQ/U=; b=ZCo3Q+0Lf3J7temjzT7CXBkqkzY8gkyaDc46L6tgp1Ew4SmDYHplmK4s4uYmzs2Tk7PDumoo5fH+Pa2ifM3Xid4TZcBkAqq20updqAeLJWdZrtz5Mrwr+MvZWcGXUWJWw2Y6F9wE/SPzSmdtUKP9AS4FyegWSPWzJR101GNAGpYaOGbtQkyXsGPifnCbWWS8IgEEUqRnwTdeKkoH95VIlVcuGw8veAiM20mdSqVLT+/6jRB/tLsXMUlIvmm40Lt8+xKmXROZ3uOT0e4DhOVewJUMsAOFTpe4bIh/ZIV+6nmMdulcz9K1qAyzkMGdPk88xoxixE9fTq3uEHnjm2Ey7Q== 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 AM0PR04MB7108.eurprd04.prod.outlook.com (2603:10a6:208:19e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.17; Tue, 3 Dec 2024 20:37:13 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.8207.017; Tue, 3 Dec 2024 20:37:13 +0000 From: Frank Li Date: Tue, 03 Dec 2024 15:36:50 -0500 Subject: [PATCH v9 1/6] platform-msi: Add msi_remove_device_irq_domain() in platform_device_msi_free_irqs_all() Message-Id: <20241203-ep-msi-v9-1-a60dbc3f15dd@nxp.com> References: <20241203-ep-msi-v9-0-a60dbc3f15dd@nxp.com> In-Reply-To: <20241203-ep-msi-v9-0-a60dbc3f15dd@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman , "Rafael J. Wysocki" , Thomas Gleixner , Anup Patel Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, jdmason@kudzu.us, Frank Li , stable@kernel.org X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1733258225; l=2997; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=VIyuF+APlHGxVbHCKBU3zVADRJEOLBTDV24SeUflb/0=; b=vHiTlC48JtEMcLt88Yc8rsnJo0HGUpGffqsnWTfzD4aEejA2hkapZO77HOE1rYIF2bbCBH/wE QMpM7qCby1CBv3d4DXMbjq2MaxKf8fFVVCF5l3kfnjS8VnqizmMfUrX X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR05CA0013.namprd05.prod.outlook.com (2603:10b6:a03:c0::26) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM0PR04MB7108:EE_ X-MS-Office365-Filtering-Correlation-Id: 1e0828e7-ff92-4701-733d-08dd13da44e9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|52116014|7416014|376014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?kraLOM056rsbDhLXzsNu/dhbDxtnt99?= =?utf-8?q?Drzy7H15vqkum3+hMmfZtRiwO8QAiHN2ZBW80RwvEizqczwaSH1wT08T5JKPusF9x?= =?utf-8?q?hDZM6thKcPsY3eUjKV5OBEFR5tAuRdDy8RuLpyo6mzQgTXQr98A3YtwrO8WckeWcJ?= =?utf-8?q?ryl6iJg0ejynRa9I45ubuP31KKhEHoXzuPBYepWdqMVCiMCXXMn2EcTm4mcIjGGNF?= =?utf-8?q?XmDdRnNv1hAm3uEnMSojReiFeLX01uHPsM/oBEl4G/Ae1c9MzlhPqHfsjbI93YUi2?= =?utf-8?q?94wCeqyYbg4aip0ospwtAmF3En3UQGi92OoKk/HXAx3YNDlBnLB21I/9z8mRq44pW?= =?utf-8?q?Yron3Ze1xCelx7C8xt92I2uU2f7+GhvZ+dc6uCH1Bi9vnUGfEZmVJ5j+kS4mSDC5Q?= =?utf-8?q?VFhey8TwSARiIrlXMofpSg0eqE7+NIudX9qaAIIjcisUrygygJWTYVJRmc9X15JGd?= =?utf-8?q?bAMuPFlRY9h9/HGq1qyn018ioYfhZQykWP66R9fVmVz/QsnDa4q9VBkKWddi6qPin?= =?utf-8?q?kHCYUGiItEHieKOprzUITOqLg84ZXN4kg+zeJzWFTfjP3e1FflqyuTO2TPv6WR+8A?= =?utf-8?q?lZX247zfEWN/YoL8K6wwnuIS8DYkwNlDJn4rwVOtb1rcIJfnrVR6oiQLxd4om8Mbg?= =?utf-8?q?ZRen/8ybTcLCd0Zt/hR2f+qZyfsKwD1EhZnPg5KFU6BRwMkPSz1QxYnoAV5pCfFlD?= =?utf-8?q?+xNDiHt0vPR+r0fZe43PQZf0ih4tOkmIpMcRf73c++IQRZfntr46+wO2e1Xs60WyJ?= =?utf-8?q?SOVq1cuAofCKJf1zrun1BiaGyePujUm77KA31QT0L0USgm5DMDE7Zi1voln+LPNhx?= =?utf-8?q?dbKnvrq+K7OlC/0GLeBtN+Eo+L3VpbI8vL59bky1D1VRk0uYRNewl2F11k2jKv77q?= =?utf-8?q?tuNGTKsAzTh4cXh5oo8qvmY+zGY3xrRI3n6vKU/IX4y+7cA/KCPzDCOPFdBRBCgcz?= =?utf-8?q?II7Sl8kKgUB3xBszB45j9peI/Ss1lFnMmkLTa6qS+fMCndbMeW066CJPJoD6Ms+QB?= =?utf-8?q?aSBBbiKAWS4eYZzqXeIGGVj6hDtIlupXChP96IV4XYXV/wGvfiZebYSGJpq2j/xSf?= =?utf-8?q?E+fD4aNEykcVifXwFEq3IGvNUv0TZdzsGGLHrJwaa4xbUtSdU8Mx9aXjygn1v/M5o?= =?utf-8?q?3m3mbrE5C+SvRVYH5dRGteglwVhC+aSFpJWdCL+AwxjEAbIcLh+eENGtul5CTzToZ?= =?utf-8?q?z5hu41vU169VRVsyoBUH03PvkdIzQ3kbHDQqYAfE0FNG6D9/1V2Z1mDW8Q0w0jglh?= =?utf-8?q?s3xsW/a/8GMYclpceNFxJrZdBnP0fh6/MZp6mQ45IxW//lroDS4iGXvGcLBmqmqHn?= =?utf-8?q?Lrajri+BQhsn/ZNMjMGYPvnfeu6BNOkU7w=3D=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)(52116014)(7416014)(376014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?69luTsMFdyzBB2hevprZCXELhQOV?= =?utf-8?q?D9z0Ux3sq9wIUj6FIebr/nXqbtiEt8QcMQiMZqeqkLxuACTpCh1mYqgqXDzpbj+0F?= =?utf-8?q?KW7qO+61NRg/2uIiABrUv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0bVYeY9IGR0nsVzmT8cBYpqA/8z0v77Nt?= =?utf-8?q?Jbw+pA8WgZp2VgOcRn97mExbeFGthZblyP9tPVZ88vWDNbOJsO03F6OS5h1013Pur?= =?utf-8?q?ZOsWWgTp2aH+U8g787lvPQ/kYHbeGk8Rcwx3DkeMY/3XkPv1/LnjG2uyc3MBgiw9D?= =?utf-8?q?sXn+sdMxiDhi4pRDsNMIl4TJI6cqyk5VT3j4sMIWTIOG2Sr4F7M6LODOaHWAl68Rb?= =?utf-8?q?2nhq57iv8HxVd5yLckkTMLvINp+H0UvVpGNSoyxmmzpm632XGVfgge9o6xti/UCRy?= =?utf-8?q?Pn9UWSCnqf9PN7F4P5/Z/U5pSUMiaDUrAVbzSsOyEYzFx8bZEXFp1QT3KdUxN3dzf?= =?utf-8?q?+EfWjXB1z23PmnET/NppXWDCF1ShkVDuCNkQvNyFK0c8Ia+ZDW5Nm+fDAonPkIz32?= =?utf-8?q?wkT4wGENbMwCVcym4Qg1zX4pvaXXwqDgZwjD4J87v4Xlo//RkZ8VW/V0RJmlGIPFQ?= =?utf-8?q?rhQkMD48CftOLcEt3wKoi1mtnMVtGkMOW2DnuvczRF1IZJ6WL//lkQZc=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1e0828e7-ff92-4701-733d-08dd13da44e9 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2024 20:37:13.7356 (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: 18JjsRs7Qv6R05+A7pPzsaKl12fGRL6C8Aw6ZSL1H8NKPJRFjsfRA6W+FCpspZrDAuNwvguxPic6Z43UlZaJRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB7108 The follow steps trigger kernel dump warning and platform_device_msi_init_and_alloc_irqs() return false. 1: platform_device_msi_init_and_alloc_irqs(); 2: platform_device_msi_free_irqs_all(); 3: platform_device_msi_init_and_alloc_irqs(); [ 76.713677] WARNING: CPU: 3 PID: 134 at kernel/irq/msi.c:1028 msi_create_device_irq_domain+0x1bc/0x22c [ 76.723010] Modules linked in: [ 76.726082] CPU: 3 UID: 0 PID: 134 Comm: kworker/3:1H Not tainted 6.13.0-rc1-00015-gd60b98003b43-dirty #57 [ 76.735741] Hardware name: NXP i.MX95 19X19 board (DT) [ 76.740883] Workqueue: kpcitest pci_epf_test_cmd_handler [ 76.746212] pstate: a0400009 (NzCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 76.753172] pc : msi_create_device_irq_domain+0x1bc/0x22c [ 76.758586] lr : msi_create_device_irq_domain+0x104/0x22c [ 76.763988] sp : ffff800083f43be0 [ 76.767313] x29: ffff800083f43be0 x28: 0000000000000000 x27: ffff8000827a7000 [ 76.774466] x26: ffff00008085f400 x25: ffff00008000b180 x24: ffff000080fc6410 [ 76.781624] x23: ffff000085704cc0 x22: ffff8000811c8828 x21: ffff000085704cc0 [ 76.788774] x20: ffff000082814000 x19: 0000000000000000 x18: ffffffffffffffff [ 76.795933] x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000 [ 76.803083] x14: 0000000000000000 x13: 0000000f00000000 x12: 0000000000000000 [ 76.810233] x11: 0000000000000000 x10: 000000000000002d x9 : ffff800083f43ba0 [ 76.817383] x8 : 00000000ffffffff x7 : 0000000000000019 x6 : ffff0000857e443a [ 76.824533] x5 : 0000000000000000 x4 : ffffffffffffffff x3 : ffff000085704ce8 [ 76.831683] x2 : ffff000080835640 x1 : 0000000000000213 x0 : ffff0000877189c0 [ 76.838840] Call trace: [ 76.841287] msi_create_device_irq_domain+0x1bc/0x22c (P) [ 76.846701] msi_create_device_irq_domain+0x104/0x22c (L) [ 76.852118] platform_device_msi_init_and_alloc_irqs+0x6c/0xb8 Do below two things in platform_device_msi_init_and_alloc_irqs(). - msi_create_device_irq_domain() - msi_domain_alloc_irqs_range() But only call msi_domain_free_irqs_all() in platform_device_msi_free_irqs_all(), which missed call msi_remove_device_irq_domain(). This cause above kernel dump when call platform_device_msi_init_and_alloc_irqs() again. Fixes: c88f9110bfbc ("platform-msi: Prepare for real per device domains") Cc: stable@kernel.org Signed-off-by: Frank Li --- drivers/base/platform-msi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/base/platform-msi.c b/drivers/base/platform-msi.c index 4401cc31e4736..e7615daf5f539 100644 --- a/drivers/base/platform-msi.c +++ b/drivers/base/platform-msi.c @@ -98,5 +98,6 @@ EXPORT_SYMBOL_GPL(platform_device_msi_init_and_alloc_irqs); void platform_device_msi_free_irqs_all(struct device *dev) { msi_domain_free_irqs_all(dev, MSI_DEFAULT_DOMAIN); + msi_remove_device_irq_domain(dev, MSI_DEFAULT_DOMAIN); } EXPORT_SYMBOL_GPL(platform_device_msi_free_irqs_all); From patchwork Tue Dec 3 20:36:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13892931 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2079.outbound.protection.outlook.com [40.107.247.79]) (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 CF458207A20; Tue, 3 Dec 2024 20:37:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.247.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733258241; cv=fail; b=jT5cepVyX9Q003HPxmOPDItYKjv97o+dl9cAvQ2sYi2Ht9fYYfWqGjZ0czG665SwudgtkxjPJY+HeG0klyg+JYTbj7HwtrVM/arH1zsjlhjaOT/VH3DQfgef4iMY2/I4k/VTlucEoYvyyx06Hmz2+4/0S3xIRWOc3CRozqtCa2E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733258241; c=relaxed/simple; bh=CYzhaaTxCf0bfjgS3xeE4SAfmPxICO3mdD1dysE5nTU=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=LyvlHfJSS+DKRLG2GtfrOfJhxakMMNL46RHkZRXcg7tuH2PFICk/vUe44SMmn8+EtR+ON4hnOCEawwGN7p7Dt5LgZAynQ4xbpZOoMXiW1gT2XZma7He7FJGGD7ywE1LMmJIOTiLT5p00GiFkp/9w9TZKfcV6/9fgaPeWVxcBcow= 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=eO5yCdF+; arc=fail smtp.client-ip=40.107.247.79 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="eO5yCdF+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tx1GMIzWCp9YOhKrYJG+n/8vta/3cwPZTcM3KdA4QkPes+2+qbDMEc/I/U2Poga3QQUv0EswXijWCdJ5Ga15zVvGII65nbu+9z0ZATnMA2kEglU40rQYQ99vBX93Fa53s5s6VO+8GJ4p6TEenCf4FwEL/5ZLIpVrRQB43gAt33Nd4dzPSzN3ZYipRTk+vwHxdyhyOhKfriRYU1PLvnmPFmOxSOvRJ2BwKprLHaZoVuDCD+kIjjvmDzDCqb5UDowTyfiClx+TbtS2uA7LwnveCQExREPlLm/aSrDHJoZuMF1pIda7XYteVDguFnhtYObdUwNWSHuzYXKVlGVJaCgFLQ== 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=Qc6rNEIOQHfLuONmH/Q5URdGsc82rTkhcNlw3A3hyEU=; b=wRvJizvCbepdDup21Bn9VpF1RL+2fM43OHsG9jxDXPnniKejuSBlK64GM6A9YheeLTrq1rtqoQ7O4gDpZ9soblzGwGB8YJW4dWb/m8GPns0jfveeaBxJymL8b0GW84rA9ICS1+/xQpCv6h4U5+FiNWbmGBJgnvhezO+lpJMKRRVifvMEY3ppIw1m+aci9eHnNKcPloJ3QEn/esRwak1X6K2LAlaD4dweJy6rA1nH5U0Spytfqs46H2qRRYczn5kpO7O5DCtxvdxwAvBDKlmXx4PCfz5Mr2BrCcGSP5Mjx9FgxSYEPl/j74SUb1ViuhnY9PWw0qhYo+7hAkhpCFmohw== 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=Qc6rNEIOQHfLuONmH/Q5URdGsc82rTkhcNlw3A3hyEU=; b=eO5yCdF+QdSToFJ03imfzf099S+YF8g+gzl5yAAiAyzbXxh0CNuo7puQFQ8XLBFoqZeb7khAvhZhwaWuAOiOpYRFRgy5vWFSMRHM02Bxold6Kz6V6csIcZkzly8dkpM6u3xCfNcXyNnz4ndX0EEIthcaLqUP498XtJ149WgGq/uxG6nQ/Pt1xmkHU5S+2fJVCwAxin1lq+7V0DlebpiYly33CYKvF2Wrb5K6tQN5DwvMHl5wtegGeP8t6lf/lRNg6K8Rhq63d6Y3fx0w0BKH4VNc+o3Vpxnpn7u/PQU8bA/XlS9uB1dtGxv8Jw54fwRgoc5hthdL63kQlPoTgK6nFg== 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 AM0PR04MB7108.eurprd04.prod.outlook.com (2603:10a6:208:19e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.17; Tue, 3 Dec 2024 20:37:18 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.8207.017; Tue, 3 Dec 2024 20:37:18 +0000 From: Frank Li Date: Tue, 03 Dec 2024 15:36:51 -0500 Subject: [PATCH v9 2/6] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Message-Id: <20241203-ep-msi-v9-2-a60dbc3f15dd@nxp.com> References: <20241203-ep-msi-v9-0-a60dbc3f15dd@nxp.com> In-Reply-To: <20241203-ep-msi-v9-0-a60dbc3f15dd@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman , "Rafael J. Wysocki" , Thomas Gleixner , Anup Patel Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1733258225; l=6716; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=CYzhaaTxCf0bfjgS3xeE4SAfmPxICO3mdD1dysE5nTU=; b=7Na5mclwPapwPDJLqjKuUX45flvuWvukbKCw2Y7BGCgWFsNBh/D0BIF4MVP3TSPe/RJRSwTCd IJdXngvQQ3IDGpRs9Gs20sSi4oVsrARSRkzzsUOQHRQEhX7G8tOgAaL X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR05CA0013.namprd05.prod.outlook.com (2603:10b6:a03:c0::26) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM0PR04MB7108:EE_ X-MS-Office365-Filtering-Correlation-Id: 51b6b03d-6a20-4aa3-5ee6-08dd13da4767 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|52116014|7416014|376014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?gDRc8UapCKmBuQA7ZTGpCoE0MAljvNp?= =?utf-8?q?K62yxBD6vruuGaUKT9FvDdUuh9LwPU0VLrkKSr75aU8urzjdvMSoBqaGsLi5FN865?= =?utf-8?q?dBNMSmUgDmXKrxKxEzy0D0N4nm384U6KyQ5K7cLO3hGTxI48hHHaymBzYDUSN4iDz?= =?utf-8?q?kccyPeW7MzUWeEimHMgo+2PYOUg/vDsy+9EpPKXA9zkpxM0PCfNCt5xY9dQbhK5H6?= =?utf-8?q?CUwqqh/yYg9z/kpvJc56BQCUBCvyKmunWKXzdmjfNIwduE2BBTOkQoG5/BmoJeMIx?= =?utf-8?q?SDz7E0r0YyG1Q1skyOk/ZaIikgwVic6e3m2kqNkSXLmkSi2nHf8G8kQ0H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7Mgt3g42f1Kc+5oTqi81W5ZV7BPaXgCA4Lpdfgo4AGG6D8hBAozvemdMhNd?= =?utf-8?q?YO7pl1fbcoD5F5lvyVEpdzRBRDRknihNIA73me5zI3JoH06Gq1WVGS35fc3c3SWl6?= =?utf-8?q?nSUenhPj4Gtct5azT0402EOU5oTtQVAmFA=3D=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)(52116014)(7416014)(376014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?HHH6vJH6xZC/v3hxwD5MkSlWN6zB?= =?utf-8?q?NOuJJOAXrYFALcYiq7/MRT0LeGBj1Pj2qR+xJYn47+XxnFZJw8YAfcSi5fBWF5COU?= =?utf-8?q?JMObC24s+oiUk/NDHVV8a9V7SfWRCb+cV0Z+N45D15N9Yn+tAwE60YfAp+qj10Bte?= =?utf-8?q?ZAcYYbjxShK2cYBuTvtqPMKsfx6qzJVlY1eI2wT+LHLU0GqRzv6uA/ichzZOSQOLe?= =?utf-8?q?W32QaxtBMs15ONw8D6ow0Tq+j7gYM6fvK+JEKkaC8kZowm/aEvzMZt6Q3OuiYIrpK?= =?utf-8?q?z2OXd0w8XrmTxGJ1DAuiNFX4UnzjWIV42xHs+gWjU+v0gO7OLGOGV3pEiFjR/8BKb?= =?utf-8?q?9O1Tea2u8eEtzba8NQZXoI0RR4qnfPQas0Vh69VszA7wb7x+mOVs7juFL2qdxWhI7?= =?utf-8?q?RG1tEUjK9+BRbZyS3a3O4bNtxwNiPCOJUex4/aYGN+kzJC6TDS2lJgheWd/tJ4J6z?= =?utf-8?q?TCkA7fp9om7fY502fSxYwY1PA2AJst8/xAxUMeFR1PkEJyiJ5GWodFPvzu83hT2Y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TVukUTjoUJdfXN668AaAj5Np/XgYWG1E3dyV9nBVlv9ePcJ1sc3MOjwazeLt6OpqW?= =?utf-8?q?E9v8F5UgePBW5jYV28M2UAEVFEvATa745j8xfJFnbHOlb5Z87dCqtvSw=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51b6b03d-6a20-4aa3-5ee6-08dd13da4767 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2024 20:37:17.9120 (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: 3smYZyPOqBZVc+eaTcNBEWOFg+xrUjCg4jwNep+YIBNHaodUWo407/meWnBnQjQV/JVVH0ucnqOlYC5mBw6qJQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB7108 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 --- Chagne from v8 to v9 - sort header file - use pci_epc_get(dev_name(msi_desc_to_dev(desc))); - check epf number at pci_epf_alloc_doorbell - Add comments for miss msi-parent case 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 | 106 ++++++++++++++++++++++++++++++++++++++ include/linux/pci-ep-msi.h | 15 ++++++ include/linux/pci-epf.h | 16 ++++++ 4 files changed, 138 insertions(+), 1 deletion(-) diff --git a/drivers/pci/endpoint/Makefile b/drivers/pci/endpoint/Makefile index 95b2fe47e3b06..a1ccce440c2c5 100644 --- a/drivers/pci/endpoint/Makefile +++ b/drivers/pci/endpoint/Makefile @@ -5,4 +5,4 @@ obj-$(CONFIG_PCI_ENDPOINT_CONFIGFS) += pci-ep-cfs.o obj-$(CONFIG_PCI_ENDPOINT) += pci-epc-core.o pci-epf-core.o\ - pci-epc-mem.o functions/ + pci-epc-mem.o pci-ep-msi.o functions/ diff --git a/drivers/pci/endpoint/pci-ep-msi.c b/drivers/pci/endpoint/pci-ep-msi.c new file mode 100644 index 0000000000000..8f92f447712d8 --- /dev/null +++ b/drivers/pci/endpoint/pci-ep-msi.c @@ -0,0 +1,106 @@ +// 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 void pci_epc_write_msi_msg(struct msi_desc *desc, struct msi_msg *msg) +{ + struct pci_epc *epc; + struct pci_epf *epf; + + epc = pci_epc_get(dev_name(msi_desc_to_dev(desc))); + if (!epc) + return; + + epf = list_first_entry_or_null(&epc->pci_epf, struct pci_epf, list); + + if (epf && epf->db_msg && desc->msi_index < epf->num_db) + memcpy(&epf->db_msg[desc->msi_index].msg, msg, sizeof(*msg)); + + pci_epc_put(epc); +} + +static void pci_epc_free_doorbell(struct pci_epc *epc, struct pci_epf *epf) +{ + guard(mutex)(&epc->lock); + + platform_device_msi_free_irqs_all(epc->dev.parent); +} + +static int pci_epc_alloc_doorbell(struct pci_epc *epc, struct pci_epf *epf) +{ + struct device *dev = epc->dev.parent; + u16 num_db = epf->num_db; + int i = 0; + int ret; + + guard(mutex)(&epc->lock); + + if (list_first_entry_or_null(&epc->pci_epf, struct pci_epf, list) != epf) { + dev_err(dev, "MSI doorbell only support one endpoint function\n"); + return -EINVAL; + } + + ret = platform_device_msi_init_and_alloc_irqs(dev, num_db, pci_epc_write_msi_msg); + if (ret) { + /* + * The pcie_ep DT node has to specify 'msi-parent' for EP + * doorbell support to work. Right now only GIC ITS is + * supported. If you have GIC ITS and reached this print, + * perhaps you are missing 'msi-parent' in DT. + */ + dev_err(dev, "Failed to allocate MSI\n"); + return -ENOMEM; + } + + for (i = 0; i < num_db; i++) + epf->db_msg[i].virq = msi_get_virq(dev, i); + + return 0; +}; + +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 num_db) +{ + struct pci_epc *epc = epf->epc; + void *msg; + int ret; + + msg = kcalloc(num_db, sizeof(struct pci_epf_doorbell_msg), GFP_KERNEL); + if (!msg) + return -ENOMEM; + + epf->num_db = num_db; + epf->db_msg = msg; + + ret = pci_epc_alloc_doorbell(epc, epf); + if (ret) + kfree(msg); + + return ret; +} +EXPORT_SYMBOL_GPL(pci_epf_alloc_doorbell); + +void pci_epf_free_doorbell(struct pci_epf *epf) +{ + struct pci_epc *epc = epf->epc; + + pci_epc_free_doorbell(epc, epf); + + kfree(epf->db_msg); + epf->db_msg = NULL; + epf->num_db = 0; +} +EXPORT_SYMBOL_GPL(pci_epf_free_doorbell); diff --git a/include/linux/pci-ep-msi.h b/include/linux/pci-ep-msi.h new file mode 100644 index 0000000000000..f0cfecf491199 --- /dev/null +++ b/include/linux/pci-ep-msi.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * PCI Endpoint *Function* side MSI header file + * + * Copyright (C) 2024 NXP + * Author: Frank Li + */ + +#ifndef __PCI_EP_MSI__ +#define __PCI_EP_MSI__ + +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 nums); +void pci_epf_free_doorbell(struct pci_epf *epf); + +#endif /* __PCI_EP_MSI__ */ diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index 18a3aeb62ae4e..5374e6515ffa0 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -12,6 +12,7 @@ #include #include #include +#include #include struct pci_epf; @@ -125,6 +126,17 @@ struct pci_epf_bar { int flags; }; +/** + * struct pci_epf_doorbell_msg - represents doorbell message + * @msi_msg: MSI message + * @virq: irq number of this doorbell MSI message + * @name: irq name for doorbell interrupt + */ +struct pci_epf_doorbell_msg { + struct msi_msg msg; + int virq; +}; + /** * struct pci_epf - represents the PCI EPF device * @dev: the PCI EPF device @@ -152,6 +164,8 @@ struct pci_epf_bar { * @vfunction_num_map: bitmap to manage virtual function number * @pci_vepf: list of virtual endpoint functions associated with this function * @event_ops: Callbacks for capturing the EPC events + * @db_msg: data for MSI from RC side + * @num_db: number of doorbells */ struct pci_epf { struct device dev; @@ -182,6 +196,8 @@ struct pci_epf { unsigned long vfunction_num_map; struct list_head pci_vepf; const struct pci_epc_event_ops *event_ops; + struct pci_epf_doorbell_msg *db_msg; + u16 num_db; }; /** From patchwork Tue Dec 3 20:36:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13892932 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2085.outbound.protection.outlook.com [40.107.247.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B89D1CEEA8; Tue, 3 Dec 2024 20:37:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.247.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733258247; cv=fail; b=eqhbCeTcU+0irtizxxDvJZH76PRoCAFeMspJwrOcDazbyrLCfalLtwPPtJikRsCja+mWb28vs7rhw2H5gbZNZPQx8/cav/C+WfyPXJNI9ILhzx9WqSqgm0m1kALxwaLgxYEIdPN+p4uDQHBdHD9PjzpAbjXqtdlEaY9XoCXMnAk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733258247; c=relaxed/simple; bh=BqHEt8m1nlQE+CROgZ5Z9jf9BfRy50ieLQvI2rOkvkU=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=RzlAM8XjbZ/6ax9rAKwARm9Fi9ScH9xH/xRotgvsdUdfEfO7u0OwoiwQEn/s3KmHZWDTklmWsJinx2MjB02GlS0McIhsFjcxJ+KsGCTcFtF80c6YTon+dhUCWrXmLI2VaqiV4wikL8s1NpAkYIecRBnbeaRPkX1hsv8yoS95UzE= 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=Rbl3AUyT; arc=fail smtp.client-ip=40.107.247.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="Rbl3AUyT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hsXuTdMnLzx4LveSjw5SPLaABPOHTcGAS2rNFdrgsyGf10T+eZUyjUsbOQ55bvEsrS9A/txaIzJRu9hniaTn8c1ccy4LOfhaXAVY4+Y5YO7S8gL/1WlliFIhNH5Fa6KyZNFQs7yXRM7Hr6a0L8c8WGeH+G6SVWgeJEP69SPdjMz8lu+7o0zcRNeDZKtmlwpIjX8VbjGrNT7n0SD0tDdviR5KcM08PLYR6sUrHFNzzTbKU1Ol+9SdV3kzbXLU17c3yI/yLaYzXrosgYJQ6eTWlaF6kCBI9MN46rQ4IC0YtEnjzY5tGwgfXjvlEqJs0wpNLp0p1TeTgOCpvv8YNkxdzQ== 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=1EtZBap3w8ZIg+WP8zXzWpJT9lQzplQNKYcUxAiAUeY=; b=iduKCd7kX5ZzXwVeEV91hLuzc2grdmNL4bhil9mAvnH9OQLE9NmP6KSMpbnS94dAmkV7JOOEP8MnoyTQlxAG7EyLKaudVa+2Klo/7tByDQWrLPorSUX1n+H+1ZDSG8+lLt0U5ZDnwz0i7Szd+HP5M+cK266BJMW+M5hK9K8Q5/ED+H8agayZdOjP5D1+d7MLVvO0xbuxz3oW1nuJ92K5jvtn3w9uJg7aicH4LBeHKECNHEWTn4j4Auj/OdND0WhMiFvy6+LdoMYbIuhN7+GRJgZBVwzu8X0tZYmOnIiP1+uCN78dw1TA6un3/CkpKBbD5AcGlgSdS6DRPNBZbFUPVA== 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=1EtZBap3w8ZIg+WP8zXzWpJT9lQzplQNKYcUxAiAUeY=; b=Rbl3AUyTXFlNQqPzo1OwiHfNwx9+u9DgF2FFT8+SjutU76j5ExbOZo+FlSI5voe5K4K7MkM/5dsjvv9OVU+Kr9xPK2jrkjqErkPf58GriJnCdzVNN1PJHPSqe1uvxuq+4Ig9FL5/EFXQDiTLEvGhIHYVlugocpk4YVHOeWJXQ/BJXPEqbD0wi/ZEHz3FfMnVKxeTavcv1YRi9BrNI78EUMNpyeAa96c+B19awoHe1L+grbKqfxCXlpuKGZ8LtLYFVICEcROFxSAgKaLlDtqxCCBUcWwXsmSc2WsTjjJ4LoDKxLx2QL6t04u+uf+qt6I4HUPTvSQAuUNyAcyYj+hOhg== 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 AM0PR04MB7108.eurprd04.prod.outlook.com (2603:10a6:208:19e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.17; Tue, 3 Dec 2024 20:37:22 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.8207.017; Tue, 3 Dec 2024 20:37:22 +0000 From: Frank Li Date: Tue, 03 Dec 2024 15:36:52 -0500 Subject: [PATCH v9 3/6] PCI: endpoint: Add pci_epf_align_inbound_addr() helper for address alignment Message-Id: <20241203-ep-msi-v9-3-a60dbc3f15dd@nxp.com> References: <20241203-ep-msi-v9-0-a60dbc3f15dd@nxp.com> In-Reply-To: <20241203-ep-msi-v9-0-a60dbc3f15dd@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman , "Rafael J. Wysocki" , Thomas Gleixner , Anup Patel Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1733258225; l=3362; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=BqHEt8m1nlQE+CROgZ5Z9jf9BfRy50ieLQvI2rOkvkU=; b=QQN5g0eQRW0rJT6T5urTDAdXuYXzc5JS03FnK/FaP3Sz8oXcUuwJ5uVfJRcVOJm5kFTecJksZ ignF7Y+w9OBBBsuHwFcRA1yWCWjv+bq+HtfFq/Mj/jzSNBJd3IFolH5 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR05CA0013.namprd05.prod.outlook.com (2603:10b6:a03:c0::26) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM0PR04MB7108:EE_ X-MS-Office365-Filtering-Correlation-Id: 12ab7f54-4cb1-4b13-d987-08dd13da49e3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|52116014|7416014|376014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?zJlSxu7LuPzhnsl6uf6F/15waykEPSK?= =?utf-8?q?t0v5UPLboGSAvYgdJUjXtAyli9xlKhdK9c6BBMWe+82gN0J2Ywts6CozAUV9aJ1PB?= =?utf-8?q?JYwd7I8YpR2z6DZeKNrwY6noSC5NyBvRJB7zZscnc9dOxVUX6q5obK4l284v4iOVq?= =?utf-8?q?GINWhMbk0RSY+BEVpAnaf5cJ7WrJzHIgY34EvLIKH8jhGidnJqx+3aUhsGL+KrrQP?= =?utf-8?q?04zoirFvX97Ijgm08eOjr8eiPXfChwbqXMi9q8AwmTUvq9V5nS0QPZONrYGJX1Bkz?= =?utf-8?q?QvS24S3MvT/Ko9DmuvvO4aWxmA98DARyULg2xEqrc7RadIq0VnULQeH0p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esUH3X/bl6l8nTtyn1?= =?utf-8?q?upDdlbJCnEVapueiNkzHLK65RoIeVudnwK1rOsHCpbu2fNyzCKgwWKNx2u8/zCB1e?= =?utf-8?q?ACxk0QEgmevNdM0ULwtKHm7QBGPFm3Ljg/aG5NjqFL4WrO1RvRGpMYvxRJwt6TQQy?= =?utf-8?q?Psilu02TaYb86qdpi42VumpGGmd4yLy3LA=3D=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)(52116014)(7416014)(376014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?gRyeQsOP8sm8ju9LGjoDLzl+fP8f?= =?utf-8?q?GDl3yajuAzO3xDPdrz6xb+VW1SuOi0TpajvGL/17NStQdrPq8W+xmWCQGy3bx6Khy?= =?utf-8?q?AP2C/j3vtlFir5ahRt7Os/nFUwdveazKhgWh78Xh0Om+qkFRgSimIf/09W3nDDxxG?= =?utf-8?q?dKVztOP0NTiXzxnkhxSEfh0RC3J+ONbVc1iqL08ToUs/WqoCNc++197UfmeOitHqg?= =?utf-8?q?rrIMTk4VK/Ng/VkHuWaG1PAxbPM8wBWMIHW95IwRHmm3lO1fPWGQFgaBzn47lGvMd?= =?utf-8?q?WYmFcb+7etkEAx8imMim7mGZeXtmcOY95wMpkMXCExccP9aoG9K10AxXbDZDJaeWT?= =?utf-8?q?pI6splowopnziK4Yson98KD3bowKyG3+2TuFjZyHZTSFXeAKbxsc+aAJCbN4CWDzd?= =?utf-8?q?WJQ37V/iZvGdYAzmV/CFTZyCeQ7ew9fhY11qQa4mTRESdMYGX8MZIjzA+YPEpzcmp?= =?utf-8?q?W15n7ZyPZyra9nDXIxufypRHDk1HzkiPwkhyYIf/tkcf9Kazhv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i87tGq9SmddYZwp+C16?= =?utf-8?q?TI4ZJb/ndGpVp4kdAN2sZivEV2jc6GSlJlgMvLNKLLyo2iEZGA2URLrsLXwlIwEIk?= =?utf-8?q?27dY67IUvvg1grqpdbhYp1eGAymDObEg2SNlRSNU6KNOcF9FhTnqoY9Y=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 12ab7f54-4cb1-4b13-d987-08dd13da49e3 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2024 20:37:22.1031 (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: reAW98dWL4AB9PC8b9g1xf6w1T6X1P4Hr2h1LadXb2MCbPLzXbFV006RJw63AJrOlZEC7d/UATzbGPNMJYGLIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB7108 Introduce the helper function pci_epf_align_inbound_addr() to adjust addresses according to PCI BAR alignment requirements, converting addresses into base and offset values. Signed-off-by: Frank Li --- change from v8 to v9 - pci_epf_align_inbound_addr(), base and off must be not NULL - rm pci_epf_align_inbound_addr_lo_hi() 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 | 44 +++++++++++++++++++++++++++++++++++++ include/linux/pci-epf.h | 3 +++ 2 files changed, 47 insertions(+) diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index 8fa2797d4169a..d7a80f9c1e661 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -464,6 +464,50 @@ struct pci_epf *pci_epf_create(const char *name) } EXPORT_SYMBOL_GPL(pci_epf_create); +/** + * pci_epf_align_inbound_addr() - Get base address and offset that match BAR'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. + * @off: return offset. + * + * 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; + + if (!base || !off) + return -EINVAL; + + epc_features = 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 = epc_features->align; + align = align ? align : 128; + if (epc_features->bar[bar].type == BAR_FIXED) + align = max(epc_features->bar[bar].fixed_size, align); + + *base = round_down(addr, align); + *off = 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 = to_pci_epf(dev); diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index 5374e6515ffa0..2847d195433bf 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -238,6 +238,9 @@ 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 bar, 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); 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); From patchwork Tue Dec 3 20:36:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13892933 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2084.outbound.protection.outlook.com [40.107.247.84]) (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 53EBF205E28; Tue, 3 Dec 2024 20:37:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.247.84 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733258251; cv=fail; b=JLR3sUO0rayG3g5LmWmEcj/dDSvmYZseWweA60M5ZPI0zhyric5dU4ylkKmHCJZucZznUnuUWFZ0nRbMuD9E/r8T0ty/8sxXyQr6LS/+Bjm6qP1P8Cerghw98mESOFMdHLa8avkkfzJBvYR4pWrYiYJ+j2rt2iYCTrmAqkLh1yA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733258251; c=relaxed/simple; bh=TLSUdRmp4K+Pa1tSim9uHX8V2yONts3GeTemgjKsAlk=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=KHKuTnvGVrKu2UACH3/2KZ/k3WwdPyKRUo0DDysax6Q3rY+N1lATHT/WsTurXuqZCqrexnX+ZdllDRif5XrvaZnl1gI+eKvXpJyfxFcsowHPIecAoGXGAXstiWGjavERLMzfkPmpGjb+6jIizOqwEGVKZVPB29rlaaKe9vYgfRo= 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=kHBZnV+k; arc=fail smtp.client-ip=40.107.247.84 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="kHBZnV+k" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YTBR2zM/WYLBYoQ0AxXjiDIqa/Nv9MjxSP+pAwn0l3lBvQtVcTWCzE87EN6F+5pZ7oAKxrARC2enQGsDKyDKFGWowPjHPff2t6uPLnt7fo8LBEBw42LfIbqzrWnMDdza2iggmr9KHAV4Mjmk5RjeTGdFSoo4YX/dPg0ekcv4gH1/7O6PtHQ4lEIwKgl9ri4MG7OrdxqW2REt+7mIk40AFk8SwjBAKplQ2jdO7OkWsJOmEP0QEtd/eQlCB9QvHNMW1mD3JNZNDNqqxOFbSXLQf0DtPn4J1GLE8NZnwQot7t3K8H5lok+bMHufUEJyfNj4EI3lmynrzCUQbEmbF2nQXQ== 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=BeYMnHiz9JJVFA6A4TlHysF/6enoLKYcE6EAntXbX1k=; b=Ba5fCSQix67hBOHWWggRt1dFTJuXl1l2y6MIDzKpb+mLE66gfZNProHVj0EZUahlfT3nLevqbatbQuRl6j/y5cpyyiGSiQNwJgA5EeTOHYss8zUTs15s+1vHyB8BI1tWCpEf+u2MJVI9ZPQDCU5Phk7Ws/wLhLjrs639aT5PzGbsDDdqwYezf6tR9pe9F7eDZkMtlYSpRgSUwSNpAUhZBOwtPIf2lW0mYR3iGq7dI6nr715Ayq8QApzMYn0LAg+ChdJDQzFdpN+HLAFJCWpbT68iy9nof2rDlvjUX8tE7Ycz9f+x2Tuk0zzMlQMpJEYZcIa50uq+XEowJm/LqJRalQ== 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=BeYMnHiz9JJVFA6A4TlHysF/6enoLKYcE6EAntXbX1k=; b=kHBZnV+kxcexcNBrrku4DSUUz+dZhpiiZHLyLdLi2nJkzZ6Qr8s2zJV3dNBgg/Zb06M4o7fY/Dhtw1C/uFfNY7dL8D2VVAAsizcsuQ4annATAnC3bIyyLCuj780v0YG5vMPAbOoCCLoRcs229pIiTLKvBPzz1EDe/RnmMVFNh+xxRSRJn3BUt+dQDs6eZsRpIUvI3WDRnQeByex6V5M11ks2GuXYcEZqdKoNeSLu2fIo9btjPsf5L3UJEW37/Z/DMKuM4+nrJGyZUg7EfX8+R/6mc6w6H9JuzcGuGe5/kny326E3PTdE+IpaCFz+djtOXmaAd3af8fB7xbawYhhIJg== 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 AM0PR04MB7108.eurprd04.prod.outlook.com (2603:10a6:208:19e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.17; Tue, 3 Dec 2024 20:37:26 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.8207.017; Tue, 3 Dec 2024 20:37:26 +0000 From: Frank Li Date: Tue, 03 Dec 2024 15:36:53 -0500 Subject: [PATCH v9 4/6] PCI: endpoint: pci-epf-test: Add doorbell test support Message-Id: <20241203-ep-msi-v9-4-a60dbc3f15dd@nxp.com> References: <20241203-ep-msi-v9-0-a60dbc3f15dd@nxp.com> In-Reply-To: <20241203-ep-msi-v9-0-a60dbc3f15dd@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman , "Rafael J. Wysocki" , Thomas Gleixner , Anup Patel Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1733258225; l=7859; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=TLSUdRmp4K+Pa1tSim9uHX8V2yONts3GeTemgjKsAlk=; b=fGJEtd0+B/foHLN/kaRCLNRuEb09muUN2U21JQ2RerUDLlgi7xhumj5uX8/NHnlGz8zNKDQqk qsH9pBQGMKVBkSo5AjLO1f2NRcgcfn3x3fomPOurttl8+eoQP4Kx7Qn X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR05CA0013.namprd05.prod.outlook.com (2603:10b6:a03:c0::26) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM0PR04MB7108:EE_ X-MS-Office365-Filtering-Correlation-Id: 5d8f2714-f677-4fbe-21ff-08dd13da4c64 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|52116014|7416014|376014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?8hnAQ1QdY+YW7KYWgKLTlduaoBrdprN?= =?utf-8?q?VhDePCIiyPxoau+zC3Z9ILwLOexgD10rBZBuYXqzkLhUCtvdCki6DUj5AvYL8/uDK?= =?utf-8?q?v3UNj33MRcxUbkl8lwqOMs5UEJdxCglwGlRLdDDpPEiWnsZb9dyzuGVMjNgCKml4g?= =?utf-8?q?wo2uHM6J/UWHgceUf6NZDDVcu/S1k9dWCoLSt+t+urOE86wA8/MpfdjQoOdOE7Dii?= =?utf-8?q?iF9g+zjBn88mhc08rQMaQFTa8acSkJe1V81qtHSjvoLzpHUCtWICQPUMCGYNDWd7t?= =?utf-8?q?soMKlgSKJrWgQz8KokNEnV578OyFxVrvBHiSPAJlORoFkVifuI1UcjwevAq8W4rQA?= =?utf-8?q?6KQlHWc7RV2i8wdvsQmRM5rgFlc+vwaMxCQbfXiOhVdEz/N0yBqgj5OyY1D8qa7Nv?= =?utf-8?q?D/RhRatDTmehxgC1l1EYhnwkD39X9xQ68HkZiAo9HH5sjObs8NFj7rj2bIwLUu0z0?= =?utf-8?q?g98sqkgj5fXuMQyqa6Aw0MZIGXMsRriH22zMU78IN56Mzc3LXVao8GBH5Le98kkQX?= =?utf-8?q?MPWJNxsRX0fedWnlLDnltBx5Zox/29yuYTtjCcvoQExZKpqoK0qI62S0QT5bN7f7N?= =?utf-8?q?f8n+rzkqQcrldJmulKdBM7EoTwqV2GaVX/O8C/H0aFtxGV56ZO6wjxk6ZMsYdv12J?= =?utf-8?q?aYwVzpZUb+O0VY8RJtpzB+Dw3vfjlqLsIh/nZh2iY+MMC8M6Hzy99YOwPNZszbci6?= =?utf-8?q?vwzyTPmvP7zaHWgKNTWRicsSXNOYcYLgfKAGqVeHsZyfit0I46hVUays4OEopxm6z?= =?utf-8?q?oWS6Di0qo5Ff8/KU9zN0Sed+FxwByCIRwJdCJKC6FGvy33qD2J4DmWGgd7/7eZX6e?= =?utf-8?q?PNxDzWLi9fCezjjZMed2R3RoeZ+kqBObnXMDeRDB8WWwTjJHLRYEV7SKqSm1Ek/is?= =?utf-8?q?wHSigORf//9KCuhkkna033WjAmt4dIqEQbTaWGV0A2qiW4+uZcJ23KrgqRNvtjiXr?= =?utf-8?q?sgPGTQqz/PjhN6RjKHreC5mvZjeUyTNuTdUrOGu6Dw9HrC71TLXG9WiJ6HF7msV5Q?= =?utf-8?q?MMDK4m8iEs9ZmlJ34UFeAJ2NkRRozxF4o+FTBjgWoRpDXu6qVX5KalOy0lYq+Pe25?= =?utf-8?q?hFQlkXRTINMb9mve6q6eYooFnoGuAf7xGjuSRqotwNw0Etnj/0UOw8632MHrvnDp8?= =?utf-8?q?RE7NYYmYcXYO1HpaOBSBOWMhES0Co3BJGlcxjlPShB5c6xAwfj1aKl9NOdU6lpDeU?= =?utf-8?q?FGeY0Co6WNw/3xcD+CRS1g2W0EcTsLOJVcD8QFNDC43TmUzZAOz4BSa7XF+/UgmRz?= =?utf-8?q?/q8z56k2H1X1kwUeoWfagtwvZ1JRDiSJkI93l/Zi0BWIqSeathA3cTtdw5rNX9vbD?= =?utf-8?q?XDJuEBOFFZ1sZwPMn/YfCY/8Y0sZsYSHQA=3D=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)(52116014)(7416014)(376014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?jQh61wwVTBJODSf2Ynn7XTsRsRNa?= =?utf-8?q?IH2mrk251f1exMJf0J7nW45vXKKi5nR2vaBrJMQRpNqFRWkXAtQkNMr6TTpHiDOcX?= =?utf-8?q?01HGSkygaSdbLuvx81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Kyfiq7GIyXlk3ni9iANzO/t2/aAsy08LcSMEV6?= =?utf-8?q?rgiNDdHdbrtkD9Zem7iZB9/PO16OxYqjzKZx3XxG1QiXQKIrD1AeUgsv+sh1ugsFB?= =?utf-8?q?cRRArSCDeiWStIUo18CF4O2Y2lieoRAonuRNbSmqRt3MelNZLzAJnO/bkMOssGl/w?= =?utf-8?q?mkF4CIwm6zcnujVBq9quG+p55qF0s0P25NfkkudjnOT1N87+kVIaH91KgYrMtWYra?= =?utf-8?q?6jEKfyvgs1mcy33Ib6tvpExg6vOkZTjDkX8lhNib/wUkJsfqo1epMSEGUvsQnUZiL?= =?utf-8?q?nZFCaGxW+hskYfdMZxeCMB5rxA7eZwXVNehc4+ix8i2YMkTrk2vviZwZjGsx/pX6X?= =?utf-8?q?eUPW+/d19ORvOexkykrDazZBXrW/UFVNTPvy/XmniZ+BzMmeLS1nEO6UFAag7kZvy?= =?utf-8?q?naQMTyE3oKXI7JWc5b7MNhEUdTbK964wiWivbdGOFlP6gTVuf8xVn6/GCMqiNjUrD?= =?utf-8?q?0x8ClYYZe5ykcj/MXrqEX4E6WugaJfsS8oS8bmMTYQUrRMDGm8thZl3Y=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d8f2714-f677-4fbe-21ff-08dd13da4c64 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2024 20:37:26.2892 (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: f33mPSi5zC6V1uCJqBUqHf5IvGN35Qf3K/5vpz5mjETmVJfgyHd8x7JCZlE2TQ5wACic9oQ4f4sPG+8Y1G4jyA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB7108 Add three registers: doorbell_bar, doorbell_addr, and doorbell_data. 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 STATUS_DOORBELL_SUCCESS in the doorbell callback to indicate completion. Avoid breaking compatibility between host and endpoint, 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 v8 to v9 - move pci_epf_alloc_doorbell() into pci_epf_{enable/disable}_doorbell(). - remove doorbell_done in commit message. - rename pci_epf_{enable/disable}_doorbell() to pci_epf_test_{enable/disable}_doorbell() to align corrent code style. 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 | 132 ++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index ef6677f34116e..a0a0e86a081cb 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -11,12 +11,14 @@ #include #include #include +#include #include #include #include #include #include +#include #include #define IRQ_TYPE_INTX 0 @@ -29,6 +31,8 @@ #define COMMAND_READ BIT(3) #define COMMAND_WRITE BIT(4) #define COMMAND_COPY BIT(5) +#define COMMAND_ENABLE_DOORBELL BIT(6) +#define COMMAND_DISABLE_DOORBELL BIT(7) #define STATUS_READ_SUCCESS BIT(0) #define STATUS_READ_FAIL BIT(1) @@ -39,6 +43,11 @@ #define STATUS_IRQ_RAISED BIT(6) #define STATUS_SRC_ADDR_INVALID BIT(7) #define STATUS_DST_ADDR_INVALID BIT(8) +#define STATUS_DOORBELL_SUCCESS BIT(9) +#define STATUS_DOORBELL_ENABLE_SUCCESS BIT(10) +#define STATUS_DOORBELL_ENABLE_FAIL BIT(11) +#define STATUS_DOORBELL_DISABLE_SUCCESS BIT(12) +#define STATUS_DOORBELL_DISABLE_FAIL BIT(13) #define FLAG_USE_DMA BIT(0) @@ -74,6 +83,9 @@ struct pci_epf_test_reg { u32 irq_type; u32 irq_number; u32 flags; + u32 doorbell_bar; + u32 doorbell_offset; + u32 doorbell_data; } __packed; static struct pci_epf_header test_header = { @@ -642,6 +654,117 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, } } +static irqreturn_t pci_epf_test_doorbell_handler(int irq, void *data) +{ + struct pci_epf_test *epf_test = data; + enum pci_barno test_reg_bar = epf_test->test_reg_bar; + struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + + reg->status |= STATUS_DOORBELL_SUCCESS; + pci_epf_test_raise_irq(epf_test, reg); + + return IRQ_HANDLED; +} + +static void pci_epf_test_doorbell_cleanup(struct pci_epf_test *epf_test) +{ + struct pci_epf_test_reg *reg = epf_test->reg[epf_test->test_reg_bar]; + struct pci_epf *epf = epf_test->epf; + + if (reg->doorbell_bar > 0) { + free_irq(epf->db_msg[0].virq, epf_test); + reg->doorbell_bar = NO_BAR; + } + + if (epf->db_msg) + pci_epf_free_doorbell(epf); +} + +static void pci_epf_test_enable_doorbell(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) +{ + struct pci_epf *epf = epf_test->epf; + struct pci_epf_bar db_bar = {}; + struct pci_epc *epc = epf->epc; + struct msi_msg *msg; + enum pci_barno bar; + size_t offset; + int ret; + + ret = pci_epf_alloc_doorbell(epf, 1); + if (ret) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + msg = &epf->db_msg[0].msg; + bar = pci_epc_get_next_free_bar(epf_test->epc_features, epf_test->test_reg_bar + 1); + if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + ret = request_irq(epf->db_msg[0].virq, pci_epf_test_doorbell_handler, 0, + "pci-test-doorbell", epf_test); + if (ret) { + dev_err(&epf->dev, + "Failed to request irq %d, doorbell feature is not supported\n", + epf->db_msg[0].virq); + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + pci_epf_test_doorbell_cleanup(epf_test); + return; + } + + reg->doorbell_data = msg->data; + reg->doorbell_bar = bar; + + msg = &epf->db_msg[0].msg; + ret = pci_epf_align_inbound_addr(epf, bar, ((u64)msg->address_hi << 32) | msg->address_lo, + &db_bar.phys_addr, &offset); + + if (ret) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + pci_epf_test_doorbell_cleanup(epf_test); + return; + } + + reg->doorbell_offset = offset; + + db_bar.barno = bar; + db_bar.size = epf->bar[bar].size; + db_bar.flags = epf->bar[bar].flags; + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &db_bar); + if (ret) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + pci_epf_test_doorbell_cleanup(epf_test); + } else { + reg->status |= STATUS_DOORBELL_ENABLE_SUCCESS; + } +} + +static void pci_epf_test_disable_doorbell(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) +{ + enum pci_barno bar = reg->doorbell_bar; + struct pci_epf *epf = epf_test->epf; + struct pci_epc *epc = epf->epc; + int ret; + + if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) { + reg->status |= STATUS_DOORBELL_DISABLE_FAIL; + return; + } + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &epf->bar[bar]); + if (ret) + reg->status |= STATUS_DOORBELL_DISABLE_FAIL; + else + reg->status |= STATUS_DOORBELL_DISABLE_SUCCESS; + + pci_epf_test_doorbell_cleanup(epf_test); +} + static void pci_epf_test_cmd_handler(struct work_struct *work) { u32 command; @@ -688,6 +811,14 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) pci_epf_test_copy(epf_test, reg); pci_epf_test_raise_irq(epf_test, reg); break; + case COMMAND_ENABLE_DOORBELL: + pci_epf_test_enable_doorbell(epf_test, reg); + pci_epf_test_raise_irq(epf_test, reg); + break; + case COMMAND_DISABLE_DOORBELL: + pci_epf_test_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; @@ -934,6 +1065,7 @@ static void pci_epf_test_unbind(struct pci_epf *epf) pci_epf_test_clean_dma_chan(epf_test); pci_epf_test_clear_bar(epf); } + pci_epf_test_doorbell_cleanup(epf_test); pci_epf_test_free_space(epf); } From patchwork Tue Dec 3 20:36:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13892934 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2083.outbound.protection.outlook.com [40.107.20.83]) (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 39F4020A5EE; Tue, 3 Dec 2024 20:37:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733258255; cv=fail; b=aN4SQEQEtBFuqy1HITwfBtoWu5q+pF/7f2OFKWsz+uATTE5fN5wva+v9LdoBHLXXE7ABE7PHkiYs2mwVn7UtYpkfSdkJq+sSiFwgowa9NQ6pf+p7AFpG1QFq/df2VemLEtT5pYJ5z0YgozW2NAGBmODP59PeEGNlEqVSFvFVPR8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733258255; c=relaxed/simple; bh=o5EKIj3vNC7YvPmJEwQfL1pJ0yVh5RKNjyYncOCamTU=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=Q/+TGzkOt4UGmGNU6iJ2Qj86QVZj+UqbxdTcqebEAVSx08ig3tJ21PgRecUUZ7jpGMldS8tCNa5DopsAs5/NKle8bROtcEqWxgL2PfQhdM/Bcgx7qmCH6q8Uk5+jLRjDBSIWR9QsXu6o7VIFE+P1LzCyOhYWhvS62c5HexJzTjM= 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=mh1EEYqH; arc=fail smtp.client-ip=40.107.20.83 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="mh1EEYqH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rLqgLeAmopfgb7DsouyC/kmPVvHs7DHct6/jogQAjoPkC2D9kqOKEiG8oD5TyYaCpZeFf/uAx1EDiyq81UyFvkqWS8E1Acg1I45WCArC/XLg7xf4xGtA6UbGDXCY/JkumCssA3iBi8/LpBUGgNpHBgrv30R6+rO5W3ASfjn6oqLUDQM/VKzIOL/dsQlROOHmMvmG0X0G8JH/1Hi09K+C3WGMPesMmjNBgVItZu+0Azy6yjWsAEMaGytgic2hT6tqrwYhnTFQRmIS2WHUW9pw9n02Z15VjmXiTAaNXNcIGIUGS9zgiShDdf9UJIiyKqWWBz2s1Vdf+yG3DvdpDWOy0g== 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=CgVPjIxixay55JQCXGUQeF5Pm0xBX2Gb/KuEgDxzx2k=; b=UBiYigYtytls4KD4whu4cXIhoLBGzeFtiDWnfKBV9ncdghF63tOzJ27E+rrsqitbMWMBAB/BMlMM1xvAoJ/WTxyqr4FB+fAUt49VxWhDnK/elo2biOcf7XA1wI++ICxq8wRRscGe34G7dXYuu0txBSU+w16FTYzaacyMjiKQAtAqVZxyzSNW7+MNiqFujGUG1AnB4TJ0H0yQLrSHj2VJStq51JjQv46L9/l+6aQRs6Za0ppxjWp2lq0k4LN/0fCIVMrQqaPacAW585SwgkWBsND2jkz7jIqefZv3+K/t/k2ns9MPsYU1iWFOu8wlYqHumA/hkXpQrd3d/O647xTh4Q== 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=CgVPjIxixay55JQCXGUQeF5Pm0xBX2Gb/KuEgDxzx2k=; b=mh1EEYqHoOwKhYgrjR8aws8noZDHurZHhqW7KAhRvvqYsdrLPl8ebAN8tsLWmNNeDT/j42FCq3zvukn9xDagv5Ub3drRXs9cqqwS8oGcGRcJsCpgMbsOfBxgnd+tE8fL3wW3GJ/ZFzWQOufZf7iTeEntjPe2k3Q19h8OK3yVtjT3Ae6VAapRPbR800jpUjzML2P/FPcMPdvLLxT6idatBVyMr4fsD6uYJ93HLpe3IU2BH7UGpBD/skZiAZYFZ7qM7PiCwHkKUo5WgpPAd5JsEtxNR9TrA1kz7LHRtm11KdIrTVkOxTmctLSlRwLocZR+Up0l7Z7TZlpAn7m66upSyQ== 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 AM9PR04MB8730.eurprd04.prod.outlook.com (2603:10a6:20b:43d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.10; Tue, 3 Dec 2024 20:37:30 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.8207.017; Tue, 3 Dec 2024 20:37:30 +0000 From: Frank Li Date: Tue, 03 Dec 2024 15:36:54 -0500 Subject: [PATCH v9 5/6] misc: pci_endpoint_test: Add doorbell test case Message-Id: <20241203-ep-msi-v9-5-a60dbc3f15dd@nxp.com> References: <20241203-ep-msi-v9-0-a60dbc3f15dd@nxp.com> In-Reply-To: <20241203-ep-msi-v9-0-a60dbc3f15dd@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman , "Rafael J. Wysocki" , Thomas Gleixner , Anup Patel Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1733258225; l=5948; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=o5EKIj3vNC7YvPmJEwQfL1pJ0yVh5RKNjyYncOCamTU=; b=1oGpdo808LSKWefQoCYEAZjxj2YrDNBTNO8Z17lkQJYo9T0m3xl48/XXkYKGIYtCv+zxgiwaG /tuFOfBMZWiDzuh797sqg1Pk8N8CuRec3c1gCfVLKh2+bWgI8hFS0J7 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR05CA0013.namprd05.prod.outlook.com (2603:10b6:a03:c0::26) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM9PR04MB8730:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b8bc1d2-873e-49eb-30f8-08dd13da4ee7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?cFQyxZ4A0BmS5HqBlijY8OipxO3ozMs?= =?utf-8?q?U9XZ+p/YONVgoVmzvho6km6ixLwGClEcjUuOy96sfu7R0OcOoHlMMqjvIfInM2If4?= =?utf-8?q?TMZ1brKQVsKjAHu/U69VtI29qSW6OGX9XbT35W1j1ZS0UF6AsD4WTeTyvH/5MT1cY?= =?utf-8?q?rn+tEF7g+XfOJxo4yr0o87XmSWJy/PAsnJjCaNmhuN96fbH5q7PPdYtIqipHWFHRp?= =?utf-8?q?noOIKFBTxgjDL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X2o4hpkSClZnscR8GytyvDo7AocDkvSrj6su6uKnPnB4R/UV3qVL5kk3AMH?= =?utf-8?q?D6tx5ulGtFM39sTHtBLSdGilzZvNAuxDHh7KVnZgYtkdEBvBJN8R+zww1HGHq2F0Q?= =?utf-8?q?rbQ13sgaWQ/WN8VR/frNmYJu64syKjLHDUK8c10DAvaGlTN3W/IitFEfGVmINagSM?= =?utf-8?q?UDW5NDbz5FsipzmaQUfw9VxnWPE0RrxMzYBNWi/Hv6uirIHncjPMwGLKuJ4Y0ACSu?= =?utf-8?q?ADhjpcUTFELCyMr3wHQR1MlWIr00Uk4igw=3D=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)(7416014)(376014)(52116014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?8dkjJKmWA/XiXoBkjSkh21oYpYH+?= =?utf-8?q?a8TxO/T2ud7oNZ84uyWNZmuuZNAu98SRfAWFcXhRYitXn7PP/yIvbvD8B7/njW/6a?= =?utf-8?q?EZXtLarmgcovzi7WLxc2PmdtAGWUwNycy2IFHPgebIRkt2c5hzwkka4jabjwWRAtH?= =?utf-8?q?ZAVQsjhA5REFEOPwtb5zpzyVWg6Ibd6jrwaR6UhitxU60GkFshhpAsMwNAKs8CoDp?= =?utf-8?q?iVNUJZC0n6zNY32UppRT0bA6pafKHszpDEp7xjOwQ//Ah0CIgc7qSjSYMcz5uFwfm?= =?utf-8?q?4YRNLSyeZdeDWFAnQZPdBvc48r0pUPeBQFjsAggEuvU1t9V3xJgS4wFuwRpjAXR2t?= =?utf-8?q?CAA0xQWfOPJwjIf8aPdQout0gagTKMPsyeMjaT1pdcivSQq/JJejNA4mIx86nG4dg?= =?utf-8?q?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q?mzPkAlTi1sPqMLQzUGmM1TMhyvfK6LjhMh2ImhS3WA5O5YCbZIf0mlSO7BRj7Kfim?= =?utf-8?q?XbMH428S+Dz7Bt/wdtj5NyoHctmpGp9gVU1+SZTBFgu9sc4g7H/6i1SmWshew2JmM?= =?utf-8?q?AhWRqEF9XV6ePsonxPAddzoZKZdKTNaawCfSuyd6CBScCNtxB7pZqY9veI09GsLHj?= =?utf-8?q?VUsWYXxFwjMScvV5beA8eTBkEt9GErswERc6nI0/FOK5eGIk7TozZors=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b8bc1d2-873e-49eb-30f8-08dd13da4ee7 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2024 20:37:30.5102 (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: 0DKSDeMt08UFTvMbLpMnRiIIUBZo6F8RhPYCs8SKprjSwnYsnKMSCm1ZcBB8M3Six+D90cjC1ZnVn7AYrvjMiw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8730 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, which host side driver miss-match with endpoint side function driver. See below table: 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 v8 to v9 - change PCITEST_DOORBELL to 0xa 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 | 80 ++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/pcitest.h | 1 + 2 files changed, 81 insertions(+) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index 3aaaf47fa4ee2..b3f36b6ba8ba2 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -42,6 +42,8 @@ #define COMMAND_READ BIT(3) #define COMMAND_WRITE BIT(4) #define COMMAND_COPY BIT(5) +#define COMMAND_ENABLE_DOORBELL BIT(6) +#define COMMAND_DISABLE_DOORBELL BIT(7) #define PCI_ENDPOINT_TEST_STATUS 0x8 #define STATUS_READ_SUCCESS BIT(0) @@ -53,6 +55,11 @@ #define STATUS_IRQ_RAISED BIT(6) #define STATUS_SRC_ADDR_INVALID BIT(7) #define STATUS_DST_ADDR_INVALID BIT(8) +#define STATUS_DOORBELL_SUCCESS BIT(9) +#define STATUS_DOORBELL_ENABLE_SUCCESS BIT(10) +#define STATUS_DOORBELL_ENABLE_FAIL BIT(11) +#define STATUS_DOORBELL_DISABLE_SUCCESS BIT(12) +#define STATUS_DOORBELL_DISABLE_FAIL BIT(13) #define PCI_ENDPOINT_TEST_LOWER_SRC_ADDR 0x0c #define PCI_ENDPOINT_TEST_UPPER_SRC_ADDR 0x10 @@ -67,6 +74,10 @@ #define PCI_ENDPOINT_TEST_IRQ_NUMBER 0x28 #define PCI_ENDPOINT_TEST_FLAGS 0x2c +#define PCI_ENDPOINT_TEST_DB_BAR 0x30 +#define PCI_ENDPOINT_TEST_DB_OFFSET 0x34 +#define PCI_ENDPOINT_TEST_DB_DATA 0x38 + #define FLAG_USE_DMA BIT(0) #define PCI_DEVICE_ID_TI_AM654 0xb00c @@ -108,6 +119,7 @@ enum pci_barno { BAR_3, BAR_4, BAR_5, + NO_BAR = -1, }; struct pci_endpoint_test { @@ -746,6 +758,71 @@ static bool pci_endpoint_test_set_irq(struct pci_endpoint_test *test, return false; } +static bool pci_endpoint_test_doorbell(struct pci_endpoint_test *test) +{ + struct pci_dev *pdev = test->pdev; + struct device *dev = &pdev->dev; + int irq_type = test->irq_type; + enum pci_barno bar; + u32 data, status; + u32 addr; + + if (irq_type < IRQ_TYPE_INTX || irq_type > IRQ_TYPE_MSIX) { + dev_err(dev, "Invalid IRQ type option\n"); + return false; + } + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, + COMMAND_ENABLE_DOORBELL); + + wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); + + status = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + if (status & STATUS_DOORBELL_ENABLE_FAIL) { + dev_err(dev, "Failed to enable doorbell\n"); + return false; + } + + data = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_DATA); + addr = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_OFFSET); + bar = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_STATUS, 0); + + bar = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR); + + writel(data, test->bar[bar] + addr); + + wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); + + status = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + + if (!(status & STATUS_DOORBELL_SUCCESS)) + dev_err(dev, "Endpoint have not received Doorbell\n"); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, + COMMAND_DISABLE_DOORBELL); + + wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); + + status |= pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + + if (status & STATUS_DOORBELL_DISABLE_FAIL) { + dev_err(dev, "Failed to disable doorbell\n"); + return false; + } + + if (!(status & STATUS_DOORBELL_SUCCESS)) + return false; + + return true; +} + static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -793,6 +870,9 @@ static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, case PCITEST_CLEAR_IRQ: ret = pci_endpoint_test_clear_irq(test); break; + case PCITEST_DOORBELL: + ret = pci_endpoint_test_doorbell(test); + break; } ret: diff --git a/include/uapi/linux/pcitest.h b/include/uapi/linux/pcitest.h index 94b46b043b536..b82e7f2ed937d 100644 --- a/include/uapi/linux/pcitest.h +++ b/include/uapi/linux/pcitest.h @@ -20,6 +20,7 @@ #define PCITEST_MSIX _IOW('P', 0x7, int) #define PCITEST_SET_IRQTYPE _IOW('P', 0x8, int) #define PCITEST_GET_IRQTYPE _IO('P', 0x9) +#define PCITEST_DOORBELL _IO('P', 0xa) #define PCITEST_CLEAR_IRQ _IO('P', 0x10) #define PCITEST_FLAGS_USE_DMA 0x00000001 From patchwork Tue Dec 3 20:36:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13892935 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2083.outbound.protection.outlook.com [40.107.20.83]) (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 2DB1A20ADC1; Tue, 3 Dec 2024 20:37:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733258258; cv=fail; b=s3Y8Dmvgiao6nNQt+xRiOVsI1vJHCAlSjg6JbuNk0EmSZubnvfeclg8w8UfUvOQAtQKc4xbisDZVuUCP/JyPFkWVNfRCdJuujclJfzJ347UivGllhTc5kkKKFjybmRmFRNM3ixZipYxZ75Tf1ynP61AbQC+hw8dkNHSrIk2a6Z0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733258258; c=relaxed/simple; bh=D6QS5dGBAjaAnBQe6gXEEbxTtlI1jz0FCsmMW1skoMA=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=s8IujtBVDQwDmM63T/e8JBDDdXs3B11WKTalygXoroyqdHGEeqgdy6mBZz1g9Illr4tdEKctLqtiyRzFU1IFSKJNN8j25t9D90chMYWUF6hGk6PtR78CVPEFrQYU6o7gmqBJ7H+h20hz45aAiULLzwaTG/4X5l6KKpJ/8i43ssM= 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=dKDkbAYB; arc=fail smtp.client-ip=40.107.20.83 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="dKDkbAYB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AA7SG7/3BKQex33NxWDJzkKALxJf9yYbrBtE07RMfXBALfpu3IiEdjjpllM8P+zEHoQj8y8EIBzzfG9wMOvQPgbKCQOR+KpKEei8QuKF8d1o7aE72kxEG7jYeF3DdqSwlwdYnkUYPLKylwoFXMRMWA+cH/JXxjgr1Xq/g+5f9jrVGC6WtBDhjsJk9z2VPSTP1HTX+RArheUmyLStW9C+EVrQjwWn3lmMh/CvJl1/9E9UVz8tFxOQn5rr4bGNkexkt/vz+hFny54vWJwrwNryLRSxcMvW+LcOyT2ChAt7AbqhI9crl/qM/tCWAMfWxl/NxGpyWwLPI6Ey/fW19s4s6Q== 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=SvAWpxw8OJYRN509YqG+wyWqM/bl2CHBc0A28i8a/jU=; b=OW5JcaV0ejAmipUsjNGjaoVSOI8dGTGsGjNWSnP9aItVtywDxTYXn76jmgO7lLG9QkKa4wi6o7wvZEZ+SKy3t/udeA2wkOmbGsIz9dMcTQ+2LdOjtZTnL/6WztsGOjYfhxjml1IHM2rQDqoHxpuZjGCcUQNFydFyhIP+bZDsVFU+yOz9rmGXb/225xsNrkwop4Eb/5j5j4Ex3R10jB3mt67aX9mDq76p7SiGXq6kjscZWfN5+zQJQKfMfx/nM+a/HEG1GpGJFdi5giuUyFKhu94VZZ0dPUBC2+/CZmkiiUAM2UCxU9QF62NWnJnIXxBUkbm8qP/guAhNxUCTNYOmPg== 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=SvAWpxw8OJYRN509YqG+wyWqM/bl2CHBc0A28i8a/jU=; b=dKDkbAYBg3vERimHNPPkxff0HubrVBC8lyIVfyYTiJjUnIDAl3AIFdyzG5ttjSHYBP9tA07PKhmMymcNLnLJKYFpBapI6Zacld1E0CiARuc6nZhel0CidpGXOFYwHO1TJBC3NtReA9qL7uwxtr4ntMp4TzkSB+GyBXCXPxXBEyPU6gWh4piXKCY5+BeX7bS4bXlpWI7OTEOctVU06l3+98FugF7IFFFnxA27XmsV6Tzb4E/eSTk3xTO6kydRAZNLKBW6VidYz2PgbJ5z8ia/roYqn4kRA2+hFH8ZEQbBDUKX+U9BGt1hYKCvinCe3k/OT4GbcJ1wM2QgQDtDXiUW+w== 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 AM9PR04MB8730.eurprd04.prod.outlook.com (2603:10a6:20b:43d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.10; Tue, 3 Dec 2024 20:37:34 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.8207.017; Tue, 3 Dec 2024 20:37:34 +0000 From: Frank Li Date: Tue, 03 Dec 2024 15:36:55 -0500 Subject: [PATCH v9 6/6] tools: PCI: Add 'B' option for test doorbell Message-Id: <20241203-ep-msi-v9-6-a60dbc3f15dd@nxp.com> References: <20241203-ep-msi-v9-0-a60dbc3f15dd@nxp.com> In-Reply-To: <20241203-ep-msi-v9-0-a60dbc3f15dd@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman , "Rafael J. Wysocki" , Thomas Gleixner , Anup Patel Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1733258225; l=1850; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=D6QS5dGBAjaAnBQe6gXEEbxTtlI1jz0FCsmMW1skoMA=; b=TuL4mT3XQxv8A9zvPGp7Rfla4KGi1wwLYktz0aij43KJ8PB8a1t2O7AkhqWfpSQOeF0p58fe9 qGrmuI2ArjsA73bujR0EgBXjr2iBnk5S63mgSJuDTI7OJeIAnTplXlq X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR05CA0013.namprd05.prod.outlook.com (2603:10b6:a03:c0::26) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM9PR04MB8730:EE_ X-MS-Office365-Filtering-Correlation-Id: 2504c42b-9611-4339-0e07-08dd13da5168 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?u/D7oyg76edchWytyxR5OYeRuoqop4o?= =?utf-8?q?vs+on1tI/hgEiQUK+yiwtIoEdHv2JBLuQMJvTxkI6xyh4moh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FAMWEUHCkaP5PNxf?= =?utf-8?q?FtWYyrL1N8ikBJTvN8j2MJmenrSW/fDpCGG4zyCm4ZHhKoQyDa72vWEIKfIpuH6i4?= =?utf-8?q?1PnIjDVjLT5KH1HpFXbFQ0I0OGS4LtY6dSg5WqiePRLe4k3oMncynRXR48tlyD99U?= =?utf-8?q?O/Lsfh/IkQ1HIkE9TrGea9d7WC7bJC6zP13gJ7w0pC2UIhjsimRPyn0rA0zdynbBr?= =?utf-8?q?vfiqcx2Dvf5kbBe45P6qDqmSVnaPvi70KmJoUB0CSVFmmtpM6y9cGsL68FB4dpFYu?= =?utf-8?q?+mrR6Lg2QhA/G0/aZd1EhihkbnbAtg4iDlokJPMQ6YtOYLtXO3pRQVcyMY9qheTds?= =?utf-8?q?ob4PwWYH43jQg6sAoAU7RuMLkfvRWHmxU2Q7KM3zIpBbf9YjiN2hiVSwD/hUEFNQh?= =?utf-8?q?2Vjtc1K/d1gB1W878NdHd4GwFYZ6gTj5oQ=3D=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)(7416014)(376014)(52116014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?4UPWswDt9J4hCzYJQeY0CQfr1Ir4?= =?utf-8?q?eza8T3OjU9BLuSAhozrbNXOuuy2WPPHULm1WmhyYpEO7vNKsAFN/+cldaMYt5pmb/?= =?utf-8?q?gbprBviP4WGLmZgwCM0z0a7WqQNqoC3XTvigfJgaHXe4f30xqWe64tmygSaGPFnOk?= =?utf-8?q?JK6p5iXuubJE15ufLBraEZxeriU8AMeIo9kwQaxj136fLteuplimF4JTvOMR1jiay?= =?utf-8?q?UHtcKwQRdt/JulZLvsCaaV+Kv5MrzvBSMG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X+ZSdDbzY/6j0hhDt6wcYpwnfiUkndsZhp?= =?utf-8?q?qX6/8Ng+mgkKeya/9x3qbJC+jb5v+hPlmyZMtZEE0NRnusE46EFf5lKyM9+1GE2iP?= =?utf-8?q?I64v6LUBTDfaye4xPMgB6SYXqxPSAKm69WP8t8fH4JnpB19/Kgp/Q5FPFpSek1scC?= =?utf-8?q?oi0eMuTP+x6l6+bESDO8lyONAMCuNDFo3fy8R8KMAwFAS+86yQertjTlD9JqY07la?= =?utf-8?q?77YxS64mgTLPga45dmqdQMhJZR4bQnJPxJxkp3G5YonOTjJXaQKabktE2gTawsC80?= =?utf-8?q?K+Pal2zXUMffGLpEOSEmLpUAcMBUstbsVOaXcJd0Z82t0Hiy+Mx8QCJ/hyCVH7ELi?= =?utf-8?q?uqKFjBy8cLVnopL2VkcpDzUjYEf3aJjJ2GFszVNiqsf2DzRhbsBKOjsM=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2504c42b-9611-4339-0e07-08dd13da5168 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2024 20:37:34.7249 (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: DrMI0qoemBFV1Mseq4rwLCM1iul79zO+m6l7r3xGyiolNDjHmDO/XjKjplgh8C8pMAkYusPYQhLTGHXRII9aYA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8730 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 7b530d838d408..fcff0224a3381 100644 --- a/tools/pci/pcitest.c +++ b/tools/pci/pcitest.c @@ -34,6 +34,7 @@ struct pci_test { bool copy; unsigned long size; bool use_dma; + bool doorbell; }; static int run_test(struct pci_test *test) @@ -147,6 +148,15 @@ static int run_test(struct pci_test *test) fprintf(stdout, "%s\n", result[ret]); } + if (test->doorbell) { + ret = ioctl(fd, PCITEST_DOORBELL, 0); + fprintf(stdout, "Ringing doorbell on the EP\t\t"); + if (ret < 0) + fprintf(stdout, "TEST FAILED\n"); + else + fprintf(stdout, "%s\n", result[ret]); + } + fflush(stdout); close(fd); return (ret < 0) ? ret : 1 - ret; /* return 0 if test succeeded */ @@ -172,7 +182,7 @@ int main(int argc, char **argv) /* set default endpoint device */ test->device = "/dev/pci-endpoint-test.0"; - while ((c = getopt(argc, argv, "D:b:m:x:i:deIlhrwcs:")) != EOF) + while ((c = getopt(argc, argv, "D:b:m:x:i:BdeIlhrwcs:")) != EOF) switch (c) { case 'D': test->device = optarg; @@ -222,6 +232,9 @@ int main(int argc, char **argv) case 'd': test->use_dma = true; continue; + case 'B': + test->doorbell = true; + continue; case 'h': default: usage: @@ -241,6 +254,7 @@ int main(int argc, char **argv) "\t-w Write buffer test\n" "\t-c Copy buffer test\n" "\t-s Size of buffer {default: 100KB}\n" + "\t-B Doorbell test\n" "\t-h Print this help message\n", argv[0]); return -EINVAL;