From patchwork Tue Oct 15 22:07:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13837310 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013029.outbound.protection.outlook.com [52.101.67.29]) (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 B44361B0F2D; Tue, 15 Oct 2024 22:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.29 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729030086; cv=fail; b=ntZzAr/mPHOJfjlg1kkG5AUGNWAc1SRD4Pb3MY3YuuvYMzJlQdU3XhODJk1zopucwPZxPLhR/NinY8y2Gl+jQsXz+AMzWRTcowOhDthzMKeZ32aDbK6oQAJuRM5BEGODT+RhzS5LVlT06SglyqLgyje14+RSywy/YWO3cccxsJA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729030086; c=relaxed/simple; bh=dpRuTumZhFUVbKPOdmtAMQ5zSKVcrdkbzwxxi6fJUz8=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=cmwufRgKtCezf12njk6VPKZs+UFu57O/wBo+HxCf/nLblHnWDkM2sQL7NVO5n3xUivZdtQ6/M5gmusUFNVNY2a8Gjf+QUYZWfnG229wBICZagGNCEseOzJ4vqDo7xNjwichxVTa0V856tXyEHNqsL/0TUAZOkLe6Er8/syEUaCk= 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=XM2y38Qp; arc=fail smtp.client-ip=52.101.67.29 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="XM2y38Qp" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ohBqd6KkVhftuO4VqhKCJENTeM4OPsaX/TSbDOIq4NHj5ufQV7ls84wbuDhB4jCbLjMNTuveU5lRJcR9MBYSpSqQj2q9xrNZzJkIbhclxph8gl6x41//Qx1DB73nAndplYNQR9OSE+jF644oftwDdx2DiEB8vwndBpN/GxSXQyG8wiiChN1NhlmFH21/5A92yhRhO7/mnzqmRq28K48gThjMd6bx7AYhleGNaHFC2xVwg8MHY+SwtenTSF8J0A0s+kO4xKBPNnMKzkiIt5vA2hEYlmmuYCSSxZ2eedxzp/Acytkt972YlKceeiWbhhnuFXtnJLMbS7LP1wVUiJn3Vg== 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=swW1eyLF2wHdo0B2Hb3YfQpGGihq8nZ9DTnuN6C2Omg=; b=o/AlepONR9l6KxO8iKKKCVDpC3+HMcZSFw/eRxOFiaJIV+Fr7hosyzH9FTGDHW/AWeT22bsL44Sm8Eq04unSTJhFsPmlFrkAMTvEfq+Wdgzb2/31hL06NvinTgJuPs4h2Pjbpd3Wii1RpDtDzeIdC8Se60Gs0jtjmcJYlYJzoOpp4KW9/xGgIYQoos4WECXaXxGhJ/JM7+JugDo69NUle98L7KzzDfGQD0AN0Wz8xJShgnoN2qOycFW3xOxQFBrUv5LzL/B6q1zhWSeK4o4vVKfjB+Qk9PIBOaghTC1Qt3goDiAN9ehn5WZHIViYScaJ7Su+HGYkspey+WcUWM4vEQ== 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=swW1eyLF2wHdo0B2Hb3YfQpGGihq8nZ9DTnuN6C2Omg=; b=XM2y38Qp8zevU7ORrcX11DucfhVs5Yp3PaFwyEV7Gh6RAJHmp7mw3umEAPiU4ltBJ7+ppoO47fi4O27IssCKYQudc8HOZKZmk9/JBqgVhvjTsKWZy2ON8uhkalGLuhk/8/ZFyxx9ejOmRv6JT0IezktEDN9tt9vFP6gl31HxgdqmbZnoUbRgjxeFeUxIMPSxQ5CIRqomVSzySDsZMN9iLzX0kmtRcnseS8AKwagMB6BPVIaP60AJvlBc9o/BvlkjzXxshV+VyKRoLguf/AkbCwZ0nQNzJOyZ+wEzZbIIOPh0hCOohtUxNf/BGJl0VDIiER3zwRO5X15nFB50gRTfrw== 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 DBBPR04MB7788.eurprd04.prod.outlook.com (2603:10a6:10:1e4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27; Tue, 15 Oct 2024 22:08:01 +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.8069.016; Tue, 15 Oct 2024 22:08:01 +0000 From: Frank Li Date: Tue, 15 Oct 2024 18:07:14 -0400 Subject: [PATCH v3 1/6] genirq/msi: Add cleanup guard define for msi_lock_descs()/msi_unlock_descs() Message-Id: <20241015-ep-msi-v3-1-cedc89a16c1a@nxp.com> References: <20241015-ep-msi-v3-0-cedc89a16c1a@nxp.com> In-Reply-To: <20241015-ep-msi-v3-0-cedc89a16c1a@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1729030073; l=791; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=dpRuTumZhFUVbKPOdmtAMQ5zSKVcrdkbzwxxi6fJUz8=; b=5WhOgWPZ4IGIHmznpYsjRFzEk+lVGdt0p3vms3BedG0LqO+CX5RpnQWxJ6ypDWH8zAPX4BuyQ ZOwIThBonCUATNAwpQ8x8Lse5nQaq11Z7nx6ERwk3vmVGnYDa2vZ8e8 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0059.namprd13.prod.outlook.com (2603:10b6:a03:2c2::34) 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_|DBBPR04MB7788:EE_ X-MS-Office365-Filtering-Correlation-Id: aa8c6dab-3e34-412b-bd6c-08dced65d5c9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA: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NJ0Pve63k7NYjB4YIe9FqtzxDeI2ptPPaI?= =?utf-8?q?G6rfvacMqlJiaBk7hlAQABjfEqni6u1WXSdxOsDyV7HJl1/2g3UtOkI3LXPXd8Vk8?= =?utf-8?q?CDSm4HShZYZZWLjj+ZgK9Jk89Bp3j3LpMEg2vdsNaw06xF+PFZH3SUVVF28E1uoAu?= =?utf-8?q?+KrvivxhoL2IA9YOYUKUIsADHWj+LYNBidk+lPdbYYYq5FPnfWHrNuEsVtwht9vJn?= =?utf-8?q?oHhr7HphWNwPKA+KPk1F4LmH4WM/jIYUTcs8GYDxVxcX4DGBvKXQePty6+sk3u6BA?= =?utf-8?q?qX9VV7n2To0rQBgkbGXOhhXVp/zmqnc8jkqz6JiwWvLx2CfE7JXJ5oytjmRwYtf4M?= =?utf-8?q?dvenenC5gNZk8MSXmPumBAWaQuQThfT7jn1fF2jqQ8WcBbRmuZVRbJ17AME07AIwQ?= =?utf-8?q?hkYKDXedHG3z9sqb5rscAdZi6I8msMjki9kZhUgI4pLcu8+EV5ZmTglm2a+NcMoOr?= =?utf-8?q?kUWQrpnt8Bejih+hmaP6NH1xrViPKGSPO1w=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)(7416014)(376014)(52116014)(366016)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?yqV0nWloKE6ZIItP5M4tRooWQSDt?= =?utf-8?q?xmlOhINEZJ6eJy8o8KnXMQQ1RwCEXessDpvKbg3dB4qFM624iSEgVUO5dVsN8CIY9?= =?utf-8?q?oCHXzjc6mvna95BNjedm5iv7BoNhIvlvoOUJF4SkULM6aIFENA0pITPDjJWYvhWAf?= =?utf-8?q?nhiGP8HWi8mJlhTyLM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94dkkyzKj/C4lFm/VSeq03DcsN1IR2fxI8gVY+y?= =?utf-8?q?Oklzr4MF627vDQeDCFaVRwX/EEFunUyH2GhXYyqyeEMGxVtLU0x7rC1HevZwvVv/V?= =?utf-8?q?P3I5ck2TpQm/iyH45JrH/AQXNXduwanU+vpkRXmz5rdURYnCbVrbYXMFVFqG5OTjE?= =?utf-8?q?rvdZxM5DbvJfb9DxJ6Ihgz8BnvtlRhmaOMgqC7pu6PZ8te77YtulkXYfOJlhBAmwM?= =?utf-8?q?lOIK6mV2HB2jcDF+s9CCF71r8F+aUyl8SOAPSa9Qd8SmpJ+UL2t4LoN22ViUfvTqe?= =?utf-8?q?K++9dWKK0tDZrtOzBXQY36qtH53bb8CcmcxVUCONXyqAwLWmGsRGK/aX9sVxPk7o2?= =?utf-8?q?WcrCqyNZCRH2X2GXy7HzpUAj0hF2DL2ySDetTgIGRR7IKVql2DpIb5SfKNOEakn4m?= =?utf-8?q?+AJpNE7iOpJyj2LqK/Ne4S+VJpI5zs4TWyTjG0WHk/YbCnnK8FCdjOP4=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: aa8c6dab-3e34-412b-bd6c-08dced65d5c9 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2024 22:08:01.4871 (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: q/42s0zFaX077BEkWmrLTbTPnk1OTKQ5RgpI7lcd+j1yblzq8jCCRrJvt/XBA0IxHOgEUQ2SGDurKjuo0bVijA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7788 Add a cleanup DEFINE_GUARD macro for msi_lock_descs() and msi_unlock_descs() to simplify lock and unlock operations in error path. Signed-off-by: Frank Li --- include/linux/msi.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/msi.h b/include/linux/msi.h index b10093c4d00ea..0b6cb7f303887 100644 --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -228,6 +228,8 @@ int msi_setup_device_data(struct device *dev); void msi_lock_descs(struct device *dev); void msi_unlock_descs(struct device *dev); +DEFINE_GUARD(msi_descs, struct device *, msi_lock_descs(_T), msi_unlock_descs(_T)) + struct msi_desc *msi_domain_first_desc(struct device *dev, unsigned int domid, enum msi_desc_filter filter); From patchwork Tue Oct 15 22:07:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13837311 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013029.outbound.protection.outlook.com [52.101.67.29]) (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 CC14A1B6D08; Tue, 15 Oct 2024 22:08:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.29 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729030088; cv=fail; b=C4w+av2ZTlSK6LnQKdozrqLwSFtlCDcqef0IvULb2cc7wg0d/M5g1fdgXZ5IFnOCLG62a4gOGMCbnDTaKjfm7tSZerN1BI0rsPsNON7R9OK/vyKxrK1TO+kTbF7MKufR3+dG05gkdHzbcT5Xf7myOMexiQP2r/FvIR/Ry5LBDyE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729030088; c=relaxed/simple; bh=UAeOGcPYB4r9eUK8PFb6MZTw8YYA0IZ33NSNOk8EfxU=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=hYAOkenwoa7MC9vww+8eqk47nkAud8jQG84xyjsTIoblIy90vbQTjtVZZLFPktTCIL29ScN7ipxy8c3VHcNuVSm8KzLqP99SDeRrHHBJmzAPSBK2EnUBbMUvYilcNWCdpp7NoJ0G61p5tzK2VrM1mZ4b6VMEPJUilqxDWxtKfYA= 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=nxN7KuKY; arc=fail smtp.client-ip=52.101.67.29 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="nxN7KuKY" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mM9s9bJMAz1R3sMLJGDRUSFZXyrydEj8M4ztuy3RlNDabdc90u2zhxKJxbh8ZO/zVgeV7QLanRWGM+LG+ltFoDtCACbjxvPCbI1h+8bHUntMXSvR1tbE3Wvkxpdoccpgy5eNTs2vbtD08j+/vjc9fqb4EfHD9xgD8yCVNjPp8eaeVl2TkeCsLUAERuL69dlLTaUXx9Dh7C1TvVWULX0rB6SbjC6nSB6KqWgcUbXnKtQDNTQTh8Y7EU1DMLXlBNkJ0vOKw5ZJaj2tQvp+MxNNJwHZLfCGVM1MooYDS9QvbhbZPZR4zQ3GfkuSdaRuwmzBIQth2/cz2ze6t+D9CwQO5Q== 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=Zr2KqpZqpb5XrDUTkmOe8bdajmgYdiot4oZ3RjQBM0w=; b=gh6SMFVlFy4yMma36jmQ+0XwDqMaKTQa824Nrn0sl5ZOjqEA9Q3h+YuguK0Ai9rZ5PW0SCy7SNn90ApmcI4QmWA4YiWJtXbWNizuzHeHS7WNuf/CTlH7uCbSh3d0IgORkKuM5Rss5lvtg3ourOhA83kqdPgndqkqWkjvttCkT0yba2hAcMSgShrocA2DiaUuOvZ7ptZosdvPWyfd/2ZMd+Gchg2BpIpYgCd4Py+vC3vjjhEKJT2vsDkAxMlG1J+6jbE8/ow7+QvzfLzyZRAbCcfuM1fPOxBn8Jl8vrcdMTWiMPCJRZV+pBBolCkOP+/Eo/leEvVxnc2QfNtHsa+llg== 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=Zr2KqpZqpb5XrDUTkmOe8bdajmgYdiot4oZ3RjQBM0w=; b=nxN7KuKYSnChn2PTYvJR+zduQlNR9YZyZNobm8Vu0f+bJ3jU72mzJPKYZocs65Lrlvdby2UtgqIbw/V6XTil5+1X6J/rTESvOpMJ/Jc/5SfW+O4WAJtrcfBucl+MCEAQ4/605JhNxLFEe2MDe2phhT9QJ0b3eQCjG5h8E/38PcCAB5OWyGLBxjCW2HyuYyI2ccsEgiqiW9kXQ6n6tCtVNUsQK2+P7rNOF9dy+MUygAsKmi7HF6NtY7kaWnHRrAJLarlQPCn8ky2kmqg8dF+pvGJjO3mo/43L8IJDDGHScBsdlff9eWQupxMcHiYHTaDRLPval1ya62kkALtaUdjoNA== 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 DBBPR04MB7788.eurprd04.prod.outlook.com (2603:10a6:10:1e4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27; Tue, 15 Oct 2024 22:08: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.8069.016; Tue, 15 Oct 2024 22:08:05 +0000 From: Frank Li Date: Tue, 15 Oct 2024 18:07:15 -0400 Subject: [PATCH v3 2/6] PCI: endpoint: Add pci_epc_get_fn() API for customizable filtering Message-Id: <20241015-ep-msi-v3-2-cedc89a16c1a@nxp.com> References: <20241015-ep-msi-v3-0-cedc89a16c1a@nxp.com> In-Reply-To: <20241015-ep-msi-v3-0-cedc89a16c1a@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1729030073; l=3066; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=UAeOGcPYB4r9eUK8PFb6MZTw8YYA0IZ33NSNOk8EfxU=; b=3F6duJQ0TcqVVtPOFL5oV8U1QskUO8PM3H1Gy7/b/4jHvG4fr5KMxRuWupP9aMcxm4cPVOV/F Mfwf/Nv//SkAkZtpcfn/hGK1qMFhqUXDzBzPdGCQDHE6V9TbZY1t5Di X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0059.namprd13.prod.outlook.com (2603:10b6:a03:2c2::34) 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_|DBBPR04MB7788:EE_ X-MS-Office365-Filtering-Correlation-Id: f5434e67-3416-4b9c-d4ec-08dced65d811 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Ztp0Xccjru7LZp3Amf9UsrcGnk0juvm?= =?utf-8?q?ctl8ZYSFRv+avNyETvqt0nSZOIwPkoIdYIKo5a/9kPz6SPAmrOj3LMAgTurENn6CL?= =?utf-8?q?xoBxxh0Yt7bx4M0MnrCGYkuPyyGMpquvu2azh80hW5MI/tFD22mMH5+TswpXGXYi8?= =?utf-8?q?27Q3HqDkVVUmSFDJWQupD5XGxeNkWPn59JDIe6WOne4PwAzNdl2sAnpYmOiiaOdTy?= =?utf-8?q?EiB2RRxps4qDRI5jpLG9r1UgLj5nwWy/hB7NKUYK5ntvgwGLYXZJmsZovuGvIfAGk?= =?utf-8?q?BMfOisopOoMeKlPNNupTeeZTwnG1dS5bOQoiaSdXC84j0GRA+TB7gm6Jmj2kinFlQ?= =?utf-8?q?kc2sL4lqbncR2MkAZhim+2aCyH+mEuy2F4aj8lntkmnUfLZUL1lltqqV+IHa6sWiI?= =?utf-8?q?yJFVsKml5eXxrVKF4CCtVXu546bOG3oJjFSYcVvs5y9kbOGBSCb+l4EvPYoztRpJx?= =?utf-8?q?8uNQlXR0uzvS/6v0HIif42YQbG+8HAD5FtUSPGkwGotyCWMLmL4xu+vFXGZlEyMPz?= =?utf-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R:;CAT:NONE;SFS:(13230040)(7416014)(376014)(52116014)(366016)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?MI31ZfHR51rID8lgTJCcd0S6FxiS?= =?utf-8?q?4oyREKgQdTs5dRjqLV+gxx8hRNH5sEoPLGo0P/iOFHgAfOITJaAz/8d1XvN8cgvuQ?= =?utf-8?q?imj29EVeWnrJgRpA2Qxztctv8kqwbH4ePEgmaVwNL+Fbq3IJdhzlql6zHhL9rNmyM?= =?utf-8?q?QJlBu4WoPbDk9KL8WuJFfhSdzvH+FxcaCO4UxyqNw8yFk7f7jxaIIsHml+PFkzm0a?= =?utf-8?q?gL4/Xeq5aNlp7HDwEqmri0zV/Sc+lyhDDBJSrEQPNHvI2VadBTIuJ0IBn80tb+CYR?= =?utf-8?q?JrZFeYXfF94Z6F67wK7+ifAIVI17wXy/JVnR0bAKOnMkUVd6WC7VWLlojolLmir23?= =?utf-8?q?b8ofTEbjEXo+ygN7ztUsum7yFJMFTBUmcdiQ2ekUfwsi5S1xv9Q4Lv9egX+uAZ5ql?= =?utf-8?q?Z55YmNalIH6dlSyNJTOM4osB90/54O3nW/rje9JQcCMA+mp4+kKDb9MTrMIXfbiAI?= =?utf-8?q?vXP6iwyz0QBbNvz3/kSLadp2IWPIG9JxzZ1sRSJ7WUQcn27VjGXepH8G5uuTq43qj?= =?utf-8?q?3Zv1SdTstk/pmUuv3ftGfEfeEbrUTcAyB8oh+tQBT+7Nu/e4bN60PUEnxdGGmh+5Z?= =?utf-8?q?IpYsiQLVM2kMccVGWvdUnKlM/1hzERRY0vBiag7tdohnLX6Zg8Rm56t8B69aW5E+y?= =?utf-8?q?yqsQDqkEqSDx3EyabmhkiCwmsPmdjXRZYENg70OFjH9upQn/UWqvxca5W9FLXulkW?= =?utf-8?q?c1sSCxtGOwywx8X33w41I7DpmRF+ysV6+gTON7F1DTp6I4sq2jCSJfiXZKOOIoqMa?= =?utf-8?q?HAK2v3Dsw+5vsf9DCL0TrjFUmNdULPLig61f8a35p5i/GB/8MF7EOhjWECaCjZO2o?= =?utf-8?q?xsBNbaOmcpN9VwU77lY6JXtfCFYfLkZiSTM/iCZzCybMew+KC8E286jTsZfAzkBTt?= =?utf-8?q?nH4oh/8dTIHYkmsqxvtRnLFwOilLmbQb5HUdGrJsthgX2wkS5IXKf94StHz+Rxkme?= =?utf-8?q?Qsc/JHdwNm/OOkFp4MqkkLY4KX9IVo1cJoFcklIrJ3bWPMaHZwzpYq5gmLjl5wcas?= =?utf-8?q?pjWrqV/FzY7zqtIjDRwLsip/8yN4gP4409kciLTOwGNDguQ/v39g8RxKyQu+r2O1O?= =?utf-8?q?I6+ahx5o4NDrSd8bDl52YSSH3wMPCRvdgi8IMwTTYigGTl8fd5Ni/1W0f61nA9IIo?= =?utf-8?q?wCNe68V1PaKv4zTD6ewVLdPMOSGGdWD+6SNO40GiB4Be2DOcYB/ePJ+dRtEX5ptaL?= =?utf-8?q?UP2MrzOJU1jmJe7/MQRLuSPln2uM+J42e5vQ3mQsFxc8Y2hBja26xbew0BCZ+FWg/?= =?utf-8?q?D7rnH/pz9015lTy864FSNA5c6WfseFC7ZwuDCMpkNgSdIFa8qAP3t+MwkIjOn3YyI?= =?utf-8?q?aRYwqwCaxWUFh/k+KT3gmzupn58EfIv6+yrdcbgxL4TzF/G/agmHQo1QL3GqQFgBM?= =?utf-8?q?ZZKIlO85xXRMgYClXrqYuWGXuVxaXQWdiJ2uT227wplgy8A5cJVtaGL+76Rvt2OhB?= =?utf-8?q?6FfmFBjlDGQdiRdgCCMkHf88lXIyP1r8MkNNffP+yQBAoAZV9HgHYgPQ=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f5434e67-3416-4b9c-d4ec-08dced65d811 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2024 22:08:05.3419 (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: 1zUJIOBKA94J9XelJrZMX5hCCdpoQXAJjgBxZ/mfBvkeehhEc8mqkJPbj4EHxQxeVHC9EgqoKOkPm94SiBZgYw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7788 Introduce the pci_epc_get_fn() API, allowing a custom filter callback function to be passed. Reimplement pci_epc_get() using pci_epc_get_fn() with a match name callback. Prepare the codebase for adding RC-to-EP doorbell support. Add DEFINE_FREE(pci_epc_put) to implement scope based auto cleanup. Signed-off-by: Frank Li --- drivers/pci/endpoint/pci-epc-core.c | 23 +++++++++++++++++++++-- include/linux/pci-epc.h | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 17f0071092550..14e6011df4b2c 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -48,6 +48,11 @@ void pci_epc_put(struct pci_epc *epc) } EXPORT_SYMBOL_GPL(pci_epc_put); +static bool pci_epc_match_name(struct device *dev, void *name) +{ + return strcmp(dev_name(dev), name) == 0; +} + /** * pci_epc_get() - get the PCI endpoint controller * @epc_name: device name of the endpoint controller @@ -56,6 +61,20 @@ EXPORT_SYMBOL_GPL(pci_epc_put); * endpoint controller */ struct pci_epc *pci_epc_get(const char *epc_name) +{ + return pci_epc_get_fn(pci_epc_match_name, (void *)epc_name); +} +EXPORT_SYMBOL_GPL(pci_epc_get); + +/** + * pci_epc_get_fn() - get the PCI endpoint controller + * @fn: callback match filter function, return true when matched + * @param: parameter for callback function fn + * + * Invoke to get struct pci_epc * corresponding to the device name of the + * endpoint controller + */ +struct pci_epc *pci_epc_get_fn(bool (*fn)(struct device *dev, void *param), void *param) { int ret = -EINVAL; struct pci_epc *epc; @@ -64,7 +83,7 @@ struct pci_epc *pci_epc_get(const char *epc_name) class_dev_iter_init(&iter, &pci_epc_class, NULL, NULL); while ((dev = class_dev_iter_next(&iter))) { - if (strcmp(epc_name, dev_name(dev))) + if (!fn(dev, param)) continue; epc = to_pci_epc(dev); @@ -82,7 +101,7 @@ struct pci_epc *pci_epc_get(const char *epc_name) class_dev_iter_exit(&iter); return ERR_PTR(ret); } -EXPORT_SYMBOL_GPL(pci_epc_get); +EXPORT_SYMBOL_GPL(pci_epc_get_fn); /** * pci_epc_get_first_free_bar() - helper to get first unreserved BAR diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index 42ef06136bd1a..682808f4510be 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -266,7 +266,9 @@ pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features); enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features *epc_features, enum pci_barno bar); struct pci_epc *pci_epc_get(const char *epc_name); +struct pci_epc *pci_epc_get_fn(bool (*fn)(struct device *dev, void *param), void *param); void pci_epc_put(struct pci_epc *epc); +DEFINE_FREE(pci_epc_put, void *, if (!(_T)) pci_epc_put(_T)) int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t base, size_t size, size_t page_size); From patchwork Tue Oct 15 22:07:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13837312 Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazon11012042.outbound.protection.outlook.com [52.101.66.42]) (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 3B3D41B0F39; Tue, 15 Oct 2024 22:08:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.66.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729030094; cv=fail; b=PUIZBdGzDm594/mq9PotPFNjxCQdhhFkyD4wiDBJgPzpw52rifU62gNZZL4D/FlaGN5WfyqhP9xN0Y6urNGRNHrT1MiiVWqJskPC0LblapwWeOI4FYL+bUR2tlK70SJO2IcbEsOJqa/2DslY8VknYtzx1fIqkY5vivHJFLKvGbo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729030094; c=relaxed/simple; bh=pJGXreHYbzV6pOZjMjyos+FLFaeZcfFY9O59zMqECaM=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=kYf64tjHUKZIU3nDGBnahWUKXcRgJZM/ywcWbwdf1mR7+s33yoAgqzal5Kc6+1UQyg4mK8Y1VY4BeuFc5lKlHC+3H7IBRDLwJCAhAOzQnbRYN4D10QhrZ5sZ+N1Ty159273OU+GxBnQK9EM2S41VOdhxTLUmignBvZlmTUDHaLw= 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=EQv1ylZq; arc=fail smtp.client-ip=52.101.66.42 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="EQv1ylZq" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qAiFxKdSqpCN8CKwUV/K0lx+Qq7LMXpW1mEtgx5lZKinQqlH5jx48RsE3NJr3iGhDoM4w3WuTtFbU58njp/QY1+txU16nx/rLKYWs0GCH9iaajotZiR119YF/37SNv+M/ddsjDFKikdUK4XWqu6xHH5E0qtZpkSZdLQwcf5cj8EpUJqjyKn4xA/BVcCLLrmSICc7Uu+lXwGPu/3x7q97QMR+u+QQrfew2G276CZUgUkMx6Bo2+sSRnHXtkrv3lDcc91olHoyxsKS2ZEY8mPZC9OGJdu7CFMF/8uyL5rZYpkxXX14l8Pj01r7pZxFq3dWEg9FF5xKHXIQ3jqsJim/eg== 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=F/9JpupgQ96f5TjTCekrzDyc6NamB8T99UcVfyvl6zs=; b=yc5QM+Uc2UDJ3zef1PrFbV9rzdPkfHMh5uwLP/5sesPL//Slp06OGrPYZJCVIZNSwrym5s5YVd394sDoIsQGA3GV9LhBGcXz2qsLH+nRtbX2T7ioJgnXkRHxnLM1rZ6+ALdYkFFXNA6FKoLOxwSEIKro2rKKC2qsO514QWRhB8eUt2le28rCNjbDxvhZLMIGE8gZv7vMEhPoWjZ3W8vMab6LLLVzcz2GnmNKxAL6HZ2+61Cv/J3siKF24zK7S7C4Beh4yUyQClSEc2k1H+pxDcyw7sjPI8x/HW1uKNihgndJjjh48vED0SA2IhKMLM1xwJN639d9TyqvYgZEqktOBg== 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=F/9JpupgQ96f5TjTCekrzDyc6NamB8T99UcVfyvl6zs=; b=EQv1ylZqRJcBPQUkLhWitkuXX7l7WXXWjUBE8UhikB4AB/17q45CNcikZsSLePKrKqOiI12ErRvcEEGzpih1x75FYBwQD2DLRl0qIl1RLGFqyl9A1p1zIm/kvk4bp4J2L0eaVMtCXl5FC4F4FVZjIxlbxXizh1LRb9u+qykR+ov8SrpVaSUbGQubBSG56fotnEMlKsod+AAi7CXhd0IKXGNY5d2rE29GpZD5fwBIMqJBurlZrqxolUvahrh2sNbiLoVu4QjMiuz3Xecf8PfLRbI2lm2qjV5qe8nZs8zm/KbxfzPEVezHah+X58PIUdlHBVnJGick3zAsyiW5b+eSYA== 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 DBBPR04MB7788.eurprd04.prod.outlook.com (2603:10a6:10:1e4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27; Tue, 15 Oct 2024 22:08:09 +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.8069.016; Tue, 15 Oct 2024 22:08:09 +0000 From: Frank Li Date: Tue, 15 Oct 2024 18:07:16 -0400 Subject: [PATCH v3 3/6] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Message-Id: <20241015-ep-msi-v3-3-cedc89a16c1a@nxp.com> References: <20241015-ep-msi-v3-0-cedc89a16c1a@nxp.com> In-Reply-To: <20241015-ep-msi-v3-0-cedc89a16c1a@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1729030073; l=7041; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=pJGXreHYbzV6pOZjMjyos+FLFaeZcfFY9O59zMqECaM=; b=9dOrBghNwgYKOSVoqa8ePrZBzQDXnWv6v/HGCIqT7GzqcBEt9LHUWSxbT6pfSib+3KLFYAbBB vPLB7hWFMFzDDskU5XhC97dPP22qC6YYuQUQtXRRIThRJ94AXPCYBGf X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0059.namprd13.prod.outlook.com (2603:10b6:a03:2c2::34) 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_|DBBPR04MB7788:EE_ X-MS-Office365-Filtering-Correlation-Id: d8a96be5-ef53-46dd-4b1f-08dced65da8a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?vUvhvxnMN66w89EUmE7O4LIHzSnsEqe?= =?utf-8?q?0wJcriPYLvp4WFl1V1wtpgHFSDK5f6+6gHpg9qWrrFWxnDOIBCAjBt1dvgJknMXwm?= =?utf-8?q?sP+WEtaT9Ea483CS16hyvZnj3Vr1+iQcyVkSyHZ/FJyzHnclaHxoci5GEVOgmsCIF?= =?utf-8?q?Km5RpJGzwgCYtdd6ZYal5mdOFWzYcMWltn3m8UnPdbletkt9QM4Z3pcqc4WqB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f-8?q?ENtdBq76YrGpTVC6Btx4uyKpWm3akYfiCC2plzfdfG3Uv5AEpbnnFjP0koWNOG3lH?= =?utf-8?q?bhXviXksvn9UptUyWNU1uDs9veqGlqkKkLR9uUGRhZRyENdFOW878AYLjIWHIkB8g?= =?utf-8?q?lcNcHrWPNUZLN9OcEKfQW2ESRY6xKlU2hfryFrMZwuJrSh2CI49bNcBy8bO7GZHDy?= =?utf-8?q?pNCdlZCevEXwAT4PVATck1IZuG5A/UStemQ=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)(7416014)(376014)(52116014)(366016)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?yM8GfKXesdLV16qLOgq+G5JtXgU7?= =?utf-8?q?oxWZ8BCVN0z4S2yy6BS4GzhU0sFQCW83yfEMCWO1KZ9B/X6MlpviQp8v2F8RUH851?= =?utf-8?q?QF576tGKLIUz7+cZB2AkDJqbpEz7LwjtqbKkT6S/yK7aalN50nMi2OLQN8YO3rdR1?= =?utf-8?q?ps8i6cMgMXGdrpmhOczzg+vrzQggdEHrdvXurQ+komNUx5qou+RWlWdoE4v6KYkzS?= =?utf-8?q?ywnK1fUFKl1NNqjfV2IsXAt+FlLDvZvG8EqNDnyD3SjtUEkqI1uA0jApaH9FGbevm?= =?utf-8?q?mVNE9ijReJGwVmM9T9KfsfuTzQEg78LXVspxS7sEexjMDxxO2SqFF1QT4my8vMwNH?= =?utf-8?q?dciAtze3LA3NS1UlIXYuHb6dT6TJNEtPvo5heM/sbs46uJ1YErOQPFM/7tOrvmlke?= =?utf-8?q?ki2tF6+xsWYLDk7i2aLvxg5MGEe/XxSDRLJ76Ebd/TuuohWuS/qs3eXy39WdmAxpX?=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f-8?q?bySCHrcLfTE+fPzVRNcwji6lNESkUEXT5OqzZ2s8mFmUHnlWGMHSA8oY6P5zHllu6?= =?utf-8?q?suk9ucxzOGpA3AuKrr32P6ib/4sGv8RntM05xiPHtOpl7mGa3bLh4ZenSBBnIPITB?= =?utf-8?q?FYEwehnv5SHAWQ/utbVcpyXwD9ikHdchAguTLPiAzqmIqy6WsXcu8kPE=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d8a96be5-ef53-46dd-4b1f-08dced65da8a X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2024 22:08:09.5112 (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: anXZuXv0Mk3VoQ/cpQ170Bm3Y+J8DB9mSvv/Rk8XtTiRnomNnrB0uIqPhRSjGLUJSCX5ggjcl1XQgRS5Z0ivQQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7788 Doorbell feature is implemented by mapping the EP's MSI interrupt controller message address to a dedicated BAR in the EPC core. It is the responsibility of the EPF driver to pass the actual message data to be written by the host to the doorbell BAR region through its own logic. Signed-off-by: Frank Li --- drivers/pci/endpoint/Makefile | 2 +- drivers/pci/endpoint/pci-ep-msi.c | 162 ++++++++++++++++++++++++++++++++++++++ include/linux/pci-ep-msi.h | 15 ++++ include/linux/pci-epf.h | 6 ++ 4 files changed, 184 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..534dcd05c435c --- /dev/null +++ b/drivers/pci/endpoint/pci-ep-msi.c @@ -0,0 +1,162 @@ +// 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 irqreturn_t pci_epf_doorbell_handler(int irq, void *data) +{ + struct pci_epf *epf = data; + struct msi_desc *desc = irq_get_msi_desc(irq); + + if (desc && epf->event_ops && epf->event_ops->doorbell) + epf->event_ops->doorbell(epf, desc->msi_index); + + return IRQ_HANDLED; +} + +static bool pci_epc_match_parent(struct device *dev, void *param) +{ + return dev->parent == param; +} + +static void pci_epc_write_msi_msg(struct msi_desc *desc, struct msi_msg *msg) +{ + struct pci_epc *epc __free(pci_epc_put) = NULL; + struct pci_epf *epf; + + epc = pci_epc_get_fn(pci_epc_match_parent, desc->dev); + + if (!epc) + return; + + /* Only support one EPF for doorbell */ + epf = list_first_entry_or_null(&epc->pci_epf, struct pci_epf, list); + if (!epf) + return; + + if (epf->msg && desc->msi_index < epf->num_db) + memcpy(epf->msg, msg, sizeof(*msg)); +} + +static int pci_epc_alloc_doorbell(struct pci_epc *epc, u8 func_no, u8 vfunc_no, int num_db) +{ + struct msi_desc *desc, *failed_desc; + struct pci_epf *epf; + struct device *dev; + int i = 0; + int ret; + + if (IS_ERR_OR_NULL(epc)) + return -EINVAL; + + /* Currently only support one func and one vfunc for doorbell */ + if (func_no || vfunc_no) + return -EINVAL; + + epf = list_first_entry_or_null(&epc->pci_epf, struct pci_epf, list); + if (!epf) + return -EINVAL; + + dev = epc->dev.parent; + ret = platform_device_msi_init_and_alloc_irqs(dev, num_db, pci_epc_write_msi_msg); + if (ret) { + dev_err(dev, "Failed to allocate MSI\n"); + return -ENOMEM; + } + + scoped_guard(msi_descs, dev) + msi_for_each_desc(desc, dev, MSI_DESC_ALL) { + ret = request_irq(desc->irq, pci_epf_doorbell_handler, 0, + kasprintf(GFP_KERNEL, "pci-epc-doorbell%d", i++), epf); + if (ret) { + dev_err(dev, "Failed to request doorbell\n"); + failed_desc = desc; + goto err_request_irq; + } + } + + return 0; + +err_request_irq: + scoped_guard(msi_descs, dev) + msi_for_each_desc(desc, dev, MSI_DESC_ALL) { + if (desc == failed_desc) + break; + kfree(free_irq(desc->irq, epf)); + } + + platform_device_msi_free_irqs_all(epc->dev.parent); + + return ret; +} + +static void pci_epc_free_doorbell(struct pci_epc *epc, u8 func_no, u8 vfunc_no) +{ + struct msi_desc *desc; + struct pci_epf *epf; + struct device *dev; + + dev = epc->dev.parent; + + scoped_guard(msi_descs, dev) + msi_for_each_desc(desc, dev, MSI_DESC_ALL) + kfree(free_irq(desc->irq, epf)); + + platform_device_msi_free_irqs_all(epc->dev.parent); +} + +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 num_db) +{ + struct pci_epc *epc; + struct device *dev; + void *msg; + int ret; + + epc = epf->epc; + dev = &epc->dev; + + guard(mutex)(&epc->lock); + + msg = kcalloc(num_db, sizeof(struct msi_msg), GFP_KERNEL); + if (!msg) + return -ENOMEM; + + epf->num_db = num_db; + epf->msg = msg; + + ret = pci_epc_alloc_doorbell(epc, epf->func_no, epf->vfunc_no, num_db); + 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; + + guard(mutex)(&epc->lock); + + epc = epf->epc; + pci_epc_free_doorbell(epc, epf->func_no, epf->vfunc_no); + + kfree(epf->msg); + epf->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..1e7e5eb4067d7 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -75,6 +75,7 @@ struct pci_epf_ops { * @link_up: Callback for the EPC link up event * @link_down: Callback for the EPC link down event * @bus_master_enable: Callback for the EPC Bus Master Enable event + * @doorbell: Callback for EPC receive MSI from RC side */ struct pci_epc_event_ops { int (*epc_init)(struct pci_epf *epf); @@ -82,6 +83,7 @@ struct pci_epc_event_ops { int (*link_up)(struct pci_epf *epf); int (*link_down)(struct pci_epf *epf); int (*bus_master_enable)(struct pci_epf *epf); + int (*doorbell)(struct pci_epf *epf, int index); }; /** @@ -152,6 +154,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 + * @msg: data for MSI from RC side + * @num_db: number of doorbells */ struct pci_epf { struct device dev; @@ -182,6 +186,8 @@ struct pci_epf { unsigned long vfunction_num_map; struct list_head pci_vepf; const struct pci_epc_event_ops *event_ops; + struct msi_msg *msg; + u16 num_db; }; /** From patchwork Tue Oct 15 22:07:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13837313 Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazon11012042.outbound.protection.outlook.com [52.101.66.42]) (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 A3C2E1D6DB1; Tue, 15 Oct 2024 22:08:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.66.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729030096; cv=fail; b=ZeEhZrrw6zjFSTFhbkYP9Lb4BnQuI/yDj0mqMzggidBCYMqEXNjTDZNRX53TvKiTM/rovv30bxJr9kEFMbJ+jroTPOZJ8efeHNBWGMhf4MLMjQHESq7VwZzED8B10G0Q5HKQxXYDx5I6ocY+iVE0z5jhAJD4+s9kTHAC3hEeDCk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729030096; c=relaxed/simple; bh=vg1b8fZ0ikOaTJqSjYHEd0OEjyDNFXGxJ24NF7GoDWk=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=HXqUXEL7nSYVe86D5R4Nlb9026Jo9avxurky2bwdb54stTqyl+5SawbPVSILJBZY9xUQGpQaYAGnKO132rrWegh4n27GH9xJpnJ597OcEWKVkdG8gx6iTPt+XXrKnPZJzS3p85OawYGK9jNXM2nc6ZyRJsPaPNEYnsIkppXE+l0= 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=U5b+XHpY; arc=fail smtp.client-ip=52.101.66.42 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="U5b+XHpY" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aXpFabaRDe3aAvALoj85336gmfzK3IS+cSAJyWvAKiJRVwXyVdXi0fZIFEgWJObduNVy+27GWjugt0HBFejnyhAXDsI070heIEdhydH+XPeGM+EwfDHpLYwAIwy3m4GrlXqB7btBadpbJOYtQsgLZWNcf5Ctv+fNTuGrcXLfU1T/S8DgaLIpvyb29O2frzn/kd5uSTt2FlLJdjIevN7lJCXFfmC6LostboKFRLsQ0paAgX1PAEcQYTjIkdtFSzRuud3WbA5aM9W2Rtv8QClK5wOioitjjp9T0jNNPXnygTmo5D4A1551mPnIbP8qE+cwIcexMPbhAaqFiFnP8Zl0fg== 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=e233vooloI8RoJJfdyVli25FRPVZrIal9Vo3c9mUtok=; b=MrvqnqlPNufN9bsl3jMkYBfXIH6E7mXiT7D7mFDjZJPqVEJaoYajjcEr6XDsbcVrEjmKUWgGdZhkwsX+VUuCy0bKXvM/6HETMk+TpJsSUuyH35WB32cosoY3tzFAEUr2OecWgKNzRSH5C8UayZJGEDsCNqKW9L7mBQwjbTz6AwPFjVPvZWtogusAV6MzhArS0FyPXY3jkahbibPqPaFU4bpfoZf1FY6jKioxc3J/MTv1Tdgy34ZTKmCT8bPSl2VGR2Ujcxh4C19d/g2LG1dkwAZQsiRWKqnhs+PvXSGoi1x2TulxiRLS8FrxCTfGk/79AUiOTs5ZWAN8C1w7AxB6qA== 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=e233vooloI8RoJJfdyVli25FRPVZrIal9Vo3c9mUtok=; b=U5b+XHpYvkhPIG95cHwg8OqhAjkc2xIkHxbhmwqJiu55VUoBW95qFt1W0o8YHYYdH12Zv97VHzey8Snkn0hFxpuq9bqyF6hTBNJqlEgEK+HsEB09pIpLA8KgrBQdMOJwWWl1/9dLeCd82rgXmijPnTzRLWeUNwWlCh8NCApfYEau/4Hp9hiPIZ6UmbfcKecAY4huKXScdghe8Xi/QL6Ui+cJNiWCEFHOptuzd0pzSlRLt53bSH9rTrZhkChv927hL3q9f9c4QCliQLlczKJqmGOKD6mwM6xbZc9f3N357QM7XO2TkF9cJyFmvn61nydNDE4arlBuCXrkYBUtn6pVkA== 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 DBBPR04MB7788.eurprd04.prod.outlook.com (2603:10a6:10:1e4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27; Tue, 15 Oct 2024 22:08: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%4]) with mapi id 15.20.8069.016; Tue, 15 Oct 2024 22:08:13 +0000 From: Frank Li Date: Tue, 15 Oct 2024 18:07:17 -0400 Subject: [PATCH v3 4/6] PCI: endpoint: pci-epf-test: Add doorbell test support Message-Id: <20241015-ep-msi-v3-4-cedc89a16c1a@nxp.com> References: <20241015-ep-msi-v3-0-cedc89a16c1a@nxp.com> In-Reply-To: <20241015-ep-msi-v3-0-cedc89a16c1a@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1729030073; l=5157; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=vg1b8fZ0ikOaTJqSjYHEd0OEjyDNFXGxJ24NF7GoDWk=; b=tm3dItJmYQGV/xS43LPWjmHikztC3AnbZl7D7Z+wQ3GrxC1/3sRNYLjPHJlmaGUdvqnaCXsGB tfP5d/mPvPAB011H898pLmyGcExmW6jX9AtvG4AGGYhgiwoL8shSIpx X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0059.namprd13.prod.outlook.com (2603:10b6:a03:2c2::34) 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_|DBBPR04MB7788:EE_ X-MS-Office365-Filtering-Correlation-Id: 1288cba9-37db-4f32-6560-08dced65dcdb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?o79n9ANHnVRAfsLVm75kszWcvCBeThQ?= =?utf-8?q?CSnagwUFCEaMx9VUpxFz99o5w/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U3UfU9/s/VowjN4Cxwt3iDX/E3PGy3h2Sj?= =?utf-8?q?sDe5HjHJN1Z9dRiolwQwPIqR5XFE+XHSmDZBo5oJZ/VQvGbSDe4HA5cEiRrveuoVT?= =?utf-8?q?pJw0VEnVYO2aGz1zsU9d7s/kvmKRW9AnCeT37WBUnXaftTZjklgmvk8iUnZllwfT9?= =?utf-8?q?AxHsa4RD0cibd7BdmSrqkMHsbXwaatgDodzRgp/LOqyYourvd7D4pRV79MmYaCmzn?= =?utf-8?q?3aaxDCF6xlkQBuZ1v6W3FbpQKf3H5y4QDm5TpOAFnevae7BGj3QffCoSB+pWwS24v?= =?utf-8?q?D2mpMU1n778McO1DRPInSGF+ACmrX04d46wEpVCIbmuIYvo7FkkD3h2/WhwiaN4tX?= =?utf-8?q?Wsv0B9oLdftDWBjdSRBsTSgWjLVR5xNCzyQ=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)(7416014)(376014)(52116014)(366016)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?rLkGwmuQ+mP4p5JOtDBpW0KOiyZE?= =?utf-8?q?Yo2HNGl0IGifG28uDoudgucuhbtW7zUZGLUCDvfwZY6YzvVJSGplE0XAIdfvkkaSP?= =?utf-8?q?okhBov0pRSWHPSiRQHEdDHTqdYmzAwHgyQzn5Kiz7M6tmYwYX7rYgu32SzKhL2dlY?= =?utf-8?q?cM6zVhU5C5LPvvUrMUzDKhmTNzWxzeUecQx+LRsxtccMwj+ORGmG1CNKMNEUutuq1?= =?utf-8?q?sKSyPWlBieDsUZ7sWEg166szosGcWcsrMopdrEVAVnrsSnPymXYNoSJnktecj5tU5?= =?utf-8?q?3JsyFqsPyv6vDUgFdp3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5JWBHT3WJEiobI9SeOA0TEvArd2fbClDl/asuezQW7+RPKXQq?= =?utf-8?q?RE1A4Q8uSZ+piVdYDcCQTaZpYpJ3RXNUQo26z2ZLkPzTupMfONNp/bM1eQyOweJqw?= =?utf-8?q?39meZsDoUswUDuEtKhUpiI3sOiYsD/2Kos104G2bl91iN9lFH6RoxrljRk3+24kh4?= =?utf-8?q?J9U1WWi2qsTGfxNZ5zi5KMW5OjfoDGdBcbkf5LWMRmORcLrzihTQXAgpdpVj3yO+b?= =?utf-8?q?oumGYLTxtiZ0ay6DLgxm52jf2thSzDYxJAziQF5G0nt4Y8MzsLJACTtUIKq9N+dFd?= =?utf-8?q?yPO+Mb32e7xbHnWbyj6xoNabHh5jT2MeytDdCyVH/Gw+ELDQa/fhsItE=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1288cba9-37db-4f32-6560-08dced65dcdb X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2024 22:08:13.3583 (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: YbGAvhfc3XY3p3nmM4S4nagpL7gAQW+47MTtUJmvTofozIv7+cxFRfDbbM/0oLHwWygRe73zhbca7YzxIoohEQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7788 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, use new PID/VID and set RevID bigger than 0. So only new pcitest program can distinguish with/without doorbell support and avoid wrongly write test data to doorbell bar. Signed-off-by: Frank Li Signed-off-by: Niklas Cassel --- drivers/pci/endpoint/functions/pci-epf-test.c | 58 ++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 7c2ed6eae53ad..c054d621353a6 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 @@ -39,6 +41,7 @@ #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 FLAG_USE_DMA BIT(0) @@ -50,6 +53,7 @@ struct pci_epf_test { void *reg[PCI_STD_NUM_BARS]; struct pci_epf *epf; enum pci_barno test_reg_bar; + enum pci_barno doorbell_bar; size_t msix_table_offset; struct delayed_work cmd_handler; struct dma_chan *dma_chan_tx; @@ -74,6 +78,9 @@ struct pci_epf_test_reg { u32 irq_type; u32 irq_number; u32 flags; + u32 doorbell_bar; + u32 doorbell_addr; + u32 doorbell_data; } __packed; static struct pci_epf_header test_header = { @@ -695,7 +702,7 @@ static int pci_epf_test_set_bar(struct pci_epf *epf) enum pci_barno test_reg_bar = epf_test->test_reg_bar; for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) { - if (!epf_test->reg[bar]) + if (!epf_test->reg[bar] && bar != epf_test->doorbell_bar) continue; ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, @@ -810,11 +817,24 @@ static int pci_epf_test_link_down(struct pci_epf *epf) return 0; } +static int pci_epf_test_doorbell(struct pci_epf *epf, int index) +{ + struct pci_epf_test *epf_test = epf_get_drvdata(epf); + 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 0; +} + static const struct pci_epc_event_ops pci_epf_test_event_ops = { .epc_init = pci_epf_test_epc_init, .epc_deinit = pci_epf_test_epc_deinit, .link_up = pci_epf_test_link_up, .link_down = pci_epf_test_link_down, + .doorbell = pci_epf_test_doorbell, }; static int pci_epf_test_alloc_space(struct pci_epf *epf) @@ -853,7 +873,7 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) if (bar == NO_BAR) break; - if (bar == test_reg_bar) + if (bar == test_reg_bar || bar == epf_test->doorbell_bar) continue; base = pci_epf_alloc_space(epf, bar_size[bar], bar, @@ -887,7 +907,11 @@ static int pci_epf_test_bind(struct pci_epf *epf) struct pci_epf_test *epf_test = epf_get_drvdata(epf); const struct pci_epc_features *epc_features; enum pci_barno test_reg_bar = BAR_0; + enum pci_barno doorbell_bar = NO_BAR; struct pci_epc *epc = epf->epc; + struct msi_msg *msg; + u64 doorbell_addr; + u32 align; if (WARN_ON_ONCE(!epc)) return -EINVAL; @@ -905,10 +929,40 @@ static int pci_epf_test_bind(struct pci_epf *epf) epf_test->test_reg_bar = test_reg_bar; epf_test->epc_features = epc_features; + align = epc_features->align; + align = align ? align : 128; + + /* Only revid >=1 support RC-to-EP Door bell */ + ret = epf->header->revid > 0 ? pci_epf_alloc_doorbell(epf, 1) : -EINVAL; + if (!ret) { + msg = epf->msg; + doorbell_bar = pci_epc_get_next_free_bar(epc_features, test_reg_bar + 1); + + if (doorbell_bar > 0) { + epf_test->doorbell_bar = doorbell_bar; + doorbell_addr = msg->address_hi; + doorbell_addr <<= 32; + doorbell_addr |= msg->address_lo; + epf->bar[doorbell_bar].phys_addr = round_down(doorbell_addr, align); + epf->bar[doorbell_bar].barno = doorbell_bar; + epf->bar[doorbell_bar].size = align; + } else { + pci_epf_free_doorbell(epf); + } + } + ret = pci_epf_test_alloc_space(epf); if (ret) return ret; + if (doorbell_bar > 0) { + struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + + reg->doorbell_addr = doorbell_addr & (align - 1); + reg->doorbell_data = msg->data; + reg->doorbell_bar = doorbell_bar; + } + return 0; } From patchwork Tue Oct 15 22:07:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13837314 Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazon11010038.outbound.protection.outlook.com [52.101.69.38]) (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 2DD8D1C9EDB; Tue, 15 Oct 2024 22:08:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.69.38 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729030102; cv=fail; b=lO5a1zql6FEa1+hHorOusLfvq6m5N9zsUZ05FwYht0sc0eKWQvh7rz7bzxJ43yzaOZTw9s8UKvWLYK9TIxK/dhTfvamnWCYytdwXYAW2W694md0CxyNYse86wnYrWjfn2P87LFxFX7oibtnZBiCxlFc1CmdSv+2KMR+foRrOpOA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729030102; c=relaxed/simple; bh=OuA7849U5QN+fJd6KNFSJXtAX3g+s+58VR7NcMSn4OE=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=t+4PlHTvp4DORXS7K52s9PzU6afdF9mDlvcDpIaCixDZG7LLs18YivT9hRSVjYy4cz164uiXX12GXQ4N+I7mlGeVyJht9wPew5CYWrFeUz+o5a7of1TZ8hV6psfjz3Rl9YtOib7QV0RqFiX/5MNYHMZpeTPm/jRInUNGfe9RCkE= 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=Q5V1lNrS; arc=fail smtp.client-ip=52.101.69.38 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="Q5V1lNrS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=x+agtq6LJB2DLR2oa9SdP6zwIGr7ms7jhKfLlEF6xv/sdS97jYtYyOWTAxVMV+1zymPfsPE/klzzAO6ysIp8xoxWzZrUFvGfVx6nL85j6Odu+cHEs5W7qfqH1MCO/iaoefpYmvZ6UDugQHrpufKIW5GJ3+Sh7uY/dXhfhNPbDthy+qt3lKoGCytLf8K+Tqy9EetWNP4N+Q/8+pBlXoFdqIjmVSSFhjoA//+YXIAAVwNzB6GOQXRGNLT+IODqH13AzLCT/GUbXEPYO3jpwTSA7ZE/StBkfZef750JyiuEH7vxvzM5Jv/9Q6382MJDtCq9BoqR1R1i5ssf/MFWhSOluQ== 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=ixq2N5yHgGG9SsucChG7MqayQqlFRic7PqHLPs/ALyU=; b=HM3w8Hq/n9aX4+WKJfAS9ua7y2qucXbhthlCLWPtcj0RDfBj9dcyRaxQ36zNDcW0/KH6N4gswmOl1eL3R1TcCflCl412GuewjELAWrjopK2ivDTDs9giicmQEzgmcN1d+IUK0qm4YcAPqz0xJ8pc8dKS90SWVu3BOOd/W104nKjvinnvkDlz3F5w+sO/eyKnKMS1QywgbC1qx7pXyDo9j6dtb3PBXiZ75Av7TGnIbsc2v1LhAA5IFL40T+04sEBPdpY36eP1Vt+XkRjdbdgvGcVsHpsK8GDRP7DEIDR8+NIUYhZotoazksCIfdHKiR3pKAV1EQzvxKRjohma/q+6gg== 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=ixq2N5yHgGG9SsucChG7MqayQqlFRic7PqHLPs/ALyU=; b=Q5V1lNrSX4oNbEuHHoSU04km2Hl4uMGmlnc8c7gkKrVv9IpNRBXmoy6Iu3Vk5Y+5FixBu7qFdS/gKVkpMWicmuXgH21JjkglUTgBzvaYb44qwhAknEq7R+aop5+tX5KfUtMAAv4mmeh5o+VcNXjABp6XhlXbJTRWK3c9K8U4j1hX+rkx9fjdX+3iuPuf176MRkLPx4JwJuia2J9hgENfUbDURUKOOi/zyljmH1fv0ZPp4IK9+xclr77U/3eF5/OQ15sROiGxg0ENhE6Jn2sQcHzU0QkUgVG5JnocBkjz5bCAXambwGl6p5yVzIMLfch5KOLrosiM6VXNGJk/52BQkw== 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 DBBPR04MB7788.eurprd04.prod.outlook.com (2603:10a6:10:1e4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27; Tue, 15 Oct 2024 22:08:17 +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.8069.016; Tue, 15 Oct 2024 22:08:17 +0000 From: Frank Li Date: Tue, 15 Oct 2024 18:07:18 -0400 Subject: [PATCH v3 5/6] misc: pci_endpoint_test: Add doorbell test case Message-Id: <20241015-ep-msi-v3-5-cedc89a16c1a@nxp.com> References: <20241015-ep-msi-v3-0-cedc89a16c1a@nxp.com> In-Reply-To: <20241015-ep-msi-v3-0-cedc89a16c1a@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1729030073; l=5945; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=OuA7849U5QN+fJd6KNFSJXtAX3g+s+58VR7NcMSn4OE=; b=JbkbUIvfNJmmZ7raOw1+A1Z4SuUrr/aGfwbaAuZ/xPbrKJdgX6iMQpL/iBlWXizVtcUl0k9OI 0fQd4gtDHJdBBBbYWkyyODK2hc16aW8plmTNr8OFbzr2IslxI7WdapG X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0059.namprd13.prod.outlook.com (2603:10b6:a03:2c2::34) 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_|DBBPR04MB7788:EE_ X-MS-Office365-Filtering-Correlation-Id: 5f5d52a3-6ec6-48de-3ec8-08dced65df28 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?JfvcU33vG9BxCZmMG1A0GQkeI1mbeDm?= =?utf-8?q?17ClnA/qezcgK0nqPWcUYNYiNfwV5wtPbLa3kcXmRirnB+4b86/PHpMk0fYrCHsyS?= =?utf-8?q?nN3K3NfrpHU/wfle5FSvYTwB8IU5AUN4axB1APdQsdFnfp2n7hCQ3w6E0PJZ3Euss?= =?utf-8?q?htZ2mtppazCgo2EKhDmB6EslcWChkefDnlPxbrEEdBrq3pRSxbFG3nYOBZE+RCGIA?= =?utf-8?q?nKlrnvSjEPvjHeTblpU0fzKMw47DZ85ii+r3/Hgiee6HdZM3h+925TkA46dz004Nu?= =?utf-8?q?nMrSialjkbBCQYbSWqnEA07rdPe1mqcVWhHTCDnixCUI1Lqy1kWRxA/nfgktcSgAq?= =?utf-8?q?PWze4dlqP9HkSazjzf6B4nTka+oCcfaHgZPFLIp73Sb+9RXwkPQbB0yxDwX0N8Kfj?= =?utf-8?q?JsxuvZja/csEaUXsgP05IZcr0JfEVbbk++k66StFeblFcnXm0e1hJ9fdZxEDL/ZIX?= =?utf-8?q?a033jiByADr3Xm+2KWaywWgrxw09053hFBdgciaN+oB1P0GixikknAPFX9wBeFiNW?= =?utf-8?q?cnd1podwyNSUF1kvUYwv3y/j2VkrUu+v3PIKd5XfJE6vA+zsUy8hkL5ygNR3ftRd5?= =?utf-8?q?ZA8/rAjPF1JcnTOexK3klrcUnWfrQ+n9WbNKMhPNrWhyTgXk9m0ZLnuRUQx1uMzGX?= =?utf-8?q?Wa6LE0uejS8tEZamKJJ5UyZYbU96tSI1xUsP4dd0yX+D2JzejYPokL9aRVpdPv9gj?= =?utf-8?q?xjpXXcswc1MSP+FqGBwiEl6XbjNklwOiB0i647HzkAz+pqgSVCDs7dRiMCe9mv2gP?= =?utf-8?q?w29PHL3HOTYF2qF3r0G6vgLzpCKhSZ54onP3SHt+0fdoJ9c5OPr2UaEeU94ATK8wN?= =?utf-8?q?kSnfu41+ta7tlHnhzVgaBPbJ9XAtFJDBO41pbnaV3aYyAuBpUTUyavxyYu4ocyIjz?= =?utf-8?q?+bSWKbT0GzM9/LQsv1028WTXTybwtoUslEcByI5h6W3H83iRCLdxAZANqnFcgP2QM?= =?utf-8?q?IZOwbfTZ1Gi69pWWuBnJRYLyZ+kgUH7Jv/1jHQ+eA9jLMBeKyOKCkY4ZI1IlMtUWf?= =?utf-8?q?VOSP20SJO+3F0n0ECVB4j44UQev6meWGKXYwoDndz235l7iiAFiAjP1sPw+W/bSH0?= =?utf-8?q?GgqfIaCA+RIbVY8YOspA43T0Q4FC/dSLr6zSUPzgnKsor0c2gM/G7t/8WyvdMU6sP?= =?utf-8?q?eWYZvZ10XHagEQVVZbG8MllefpQlHdT9/p/EyWqsOk99BBqy8APHj6KgJMSSTbBTY?= =?utf-8?q?Rlq06k+7e4jvD0Fu2ySjyMZBwCR0l0skbwXPtpAL/AZ1S3RiA3Xbt6YAR+HWx6GA9?= =?utf-8?q?V5LgqssbFLsuvIDBuw3lJSG+EpqbUZHTe1g=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)(7416014)(376014)(52116014)(366016)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?bklggGjlVECMcTVH9x4LjdugN2D7?= =?utf-8?q?3uZgVBoDa4SUHeydcGLJ33Nx/Gdn0741UzaB/kKcr1wknBzsQAMElTKFYSE65qtbX?= =?utf-8?q?fYwT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rjL6zhEgqIs9cnbsRcpVAp3rAGkPln25MFqkC5k+hPGOa?= =?utf-8?q?qpyCuz6syDbrN+2xymGTSE2p3zVbRBBAcfqcFU5ByzqXIkMPsFwUSaoLWyhcmMEQa?= =?utf-8?q?V7D+rJkcI2CFcYHTLMkmGu8AMru7AA5S5ZaFRA7t8kzLYvkjsob+vOGtR9wSbQltA?= =?utf-8?q?BDM2M3ATh8IwJf4PJbR7iY+MPUepdi4GXQTrO+MVxekjUoJvb02yvHLAH6iVO531c?= =?utf-8?q?fw8BpXT2F135pFxub33OjnJC2ADDb+Y8KygrA4Q5kmcI/zVa3w1I9dL8pM/pD+Ac+?= =?utf-8?q?hK6YpG6zOEDNJARZHUs3d169IP6Xy3zF0BDnFL4tnxM7hauqgq5ge/3++xDkcWMa4?= =?utf-8?q?caFkKslbS58jSAHnZlnpPB8MiEIlcK6QlB6SNrzWZ0LbrWfNxGrzZxyLze2T8mAdT?= =?utf-8?q?UtMNz6LfkxDhV17oSiWwEvvd4iMORjqJiUedALn8FDNEHwOXmQdrjg8L2Kz3cZ2LK?= =?utf-8?q?Xh69INr2wy1GHFnh7dxUwK/AU7N8WHUI7b787d68gMr/T5Q1NaFk49xw=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5f5d52a3-6ec6-48de-3ec8-08dced65df28 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2024 22:08:17.2277 (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: msbM90+ebZPYKQpHhFvXvvFiHlDHm6HDjPCZA9PSUeKkGxGbp58DvKoBto9eF7Fz2BWUmCWPUAqHYpw+JDWavQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7788 Add three registers: PCIE_ENDPOINT_TEST_DB_BAR, PCIE_ENDPOINT_TEST_DB_ADDR, and PCIE_ENDPOINT_TEST_DB_DATA. Trigger the doorbell by writing data from PCI_ENDPOINT_TEST_DB_DATA to the address provided by PCI_ENDPOINT_TEST_DB_ADDR and wait for endpoint feedback. Enable doorbell support only for PCI_DEVICE_ID_IMX8_DB, while other devices keep the same behavior as before. EP side RC with old driver RC with new driver PCI_DEVICE_ID_IMX8_DB no probe doorbell enabled Other device ID doorbell disabled* doorbell disabled* * Behavior remains unchanged. Return failure if pcitest try to test doorbell bar. Signed-off-by: Frank Li --- drivers/misc/pci_endpoint_test.c | 60 ++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/pcitest.h | 1 + 2 files changed, 61 insertions(+) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index 3aaaf47fa4ee2..a2b68c613c782 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -53,6 +53,7 @@ #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 PCI_ENDPOINT_TEST_LOWER_SRC_ADDR 0x0c #define PCI_ENDPOINT_TEST_UPPER_SRC_ADDR 0x10 @@ -67,7 +68,12 @@ #define PCI_ENDPOINT_TEST_IRQ_NUMBER 0x28 #define PCI_ENDPOINT_TEST_FLAGS 0x2c +#define PCI_ENDPOINT_TEST_DB_BAR 0x30 +#define PCI_ENDPOINT_TEST_DB_ADDR 0x34 +#define PCI_ENDPOINT_TEST_DB_DATA 0x38 + #define FLAG_USE_DMA BIT(0) +#define FLAG_SUPPORT_DOORBELL BIT(1) #define PCI_DEVICE_ID_TI_AM654 0xb00c #define PCI_DEVICE_ID_TI_J7200 0xb00f @@ -75,6 +81,7 @@ #define PCI_DEVICE_ID_TI_J721S2 0xb013 #define PCI_DEVICE_ID_LS1088A 0x80c0 #define PCI_DEVICE_ID_IMX8 0x0808 +#define PCI_DEVICE_ID_IMX8_DB 0x080c #define is_am654_pci_dev(pdev) \ ((pdev)->device == PCI_DEVICE_ID_TI_AM654) @@ -108,6 +115,7 @@ enum pci_barno { BAR_3, BAR_4, BAR_5, + NO_BAR = -1, }; struct pci_endpoint_test { @@ -124,12 +132,14 @@ struct pci_endpoint_test { enum pci_barno test_reg_bar; size_t alignment; const char *name; + bool support_db; }; struct pci_endpoint_test_data { enum pci_barno test_reg_bar; size_t alignment; int irq_type; + bool support_db; }; static inline u32 pci_endpoint_test_readl(struct pci_endpoint_test *test, @@ -746,6 +756,39 @@ 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) +{ + enum pci_barno bar; + u32 data, status; + u32 addr; + + if (!test->support_db) + return false; + + bar = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR); + if (bar == NO_BAR) + return false; + + data = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_DATA); + addr = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_ADDR); + bar = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_STATUS, 0); + + 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) + return true; + + return false; +} + static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -762,6 +805,9 @@ static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, switch (cmd) { case PCITEST_BAR: bar = arg; + if (test->support_db && + bar == pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR)) + goto ret; if (bar > BAR_5) goto ret; if (is_am654_pci_dev(pdev) && bar == BAR_0) @@ -793,6 +839,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: @@ -839,6 +888,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev, test_reg_bar = data->test_reg_bar; test->test_reg_bar = test_reg_bar; test->alignment = data->alignment; + test->support_db = data->support_db; irq_type = data->irq_type; } @@ -986,6 +1036,13 @@ static const struct pci_endpoint_test_data default_data = { .irq_type = IRQ_TYPE_MSI, }; +static const struct pci_endpoint_test_data default_data_db = { + .test_reg_bar = BAR_0, + .alignment = SZ_4K, + .irq_type = IRQ_TYPE_MSI, + .support_db = true, +}; + static const struct pci_endpoint_test_data am654_data = { .test_reg_bar = BAR_2, .alignment = SZ_64K, @@ -1017,6 +1074,9 @@ static const struct pci_device_id pci_endpoint_test_tbl[] = { .driver_data = (kernel_ulong_t)&default_data, }, { PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, PCI_DEVICE_ID_IMX8),}, + { PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, PCI_DEVICE_ID_IMX8_DB), + .driver_data = (kernel_ulong_t)&default_data_db, + }, { PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, PCI_DEVICE_ID_LS1088A), .driver_data = (kernel_ulong_t)&default_data, }, diff --git a/include/uapi/linux/pcitest.h b/include/uapi/linux/pcitest.h index 94b46b043b536..06d9f548b510e 100644 --- a/include/uapi/linux/pcitest.h +++ b/include/uapi/linux/pcitest.h @@ -21,6 +21,7 @@ #define PCITEST_SET_IRQTYPE _IOW('P', 0x8, int) #define PCITEST_GET_IRQTYPE _IO('P', 0x9) #define PCITEST_CLEAR_IRQ _IO('P', 0x10) +#define PCITEST_DOORBELL _IO('P', 0x11) #define PCITEST_FLAGS_USE_DMA 0x00000001 From patchwork Tue Oct 15 22:07:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13837315 Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazon11010038.outbound.protection.outlook.com [52.101.69.38]) (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 81F181F80C9; Tue, 15 Oct 2024 22:08:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.69.38 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729030104; cv=fail; b=uxI/J0Z4r5HfjavCa+HVxqe574YnX1qsrq1/PipLWQ3AdOlArrZQ877KA/nRANODPdyeS1nwC3EZIERf+gWHKYuZjQiKQeocoXFeOsSOaybe+xK831WWybcHzdUmxRcYTzWL1MZk/wSf1f3iHgEZH/KohA8RWHE3PMLAa2Xptz0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729030104; c=relaxed/simple; bh=oLfeRG2JJa/EVak0ZqRbgfNgEQ6xhDK04ybgk4QBnh0=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=cLrrJ36LvMGMaaNTZZXXaFAV/pOHD/bXkEgTGscFeju7fbIoRnJr4eJYEaGQEuQkzWyUvrJp146eQIjh88N/xlEQVPqiaMqdP7PRwee/95C0AAs7S0EORWyMWtolZYJoAw6srkqe5TH+zClUJkWPvIHOOTfLagCvQhm27cXezoc= 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=KYtdnDXi; arc=fail smtp.client-ip=52.101.69.38 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="KYtdnDXi" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=s8WBViq283QXcCinzg3aplHWoRzFUnl8i3FDBhYiPtKAA9xSSxhDdmjI6DIyF7iXNpjo5MRPjpzMp8fqHSyxYspk0LnzTRM4fYBTr4IEQObc5Zo3Z5dVH4X87XtnaaVCA1mkbmcRdQCl+Z/WjnSeMuHZVI97dd68hTDUNAz8Xy39jCGt5noXY4tcAitreTSlHQw5VKqS+WXZ611lQuks8BkhppqLFg+rhCptvZ1b5sgDHOi0J5HxHoHYaQETpCiKzcbPZqbmFYuwp9g2MCdmrGsXweXdje6P8PU+aM2XBQ/jFHTeLx+Fz7qG4wXV/Yq71ubF4KtGtsN4I1or74GRqw== 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=HRw0nM+ngMAE6u8ALv623oDL1F1mp7li7piBbTWnJ98=; b=w4A3a/zZKuEeGeqz8d/W1Qx4TIbXkAtMNpBOtpd6BPzNhWiN+NEDxoT2vmZui3/cYGqify9UMilIvC3NZLV7//+vCAsvKVhS8q3KRVjcTIPKookdoDE1Ag8EggZ/Zj9YUuFdSsBftCL+ftni5kXZtg4C9Bfv78TV8kVLwyrKAIUoTk0aIJCGxMz3IbpUg0FpHjRLpgfwUCSuYKEGN4RjncaV3ayRL98bPPRElWBwi7t/n3KTn8q04mmwnJOKMJoH4lOUuPPA1sp2ad4mozlkbKHC1IUs0XDaqnYpxaEQcYtMg9RfP+gQeXoPxcZEo4DUP3xU4EtvpqdpaVe8UUEdJw== 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=HRw0nM+ngMAE6u8ALv623oDL1F1mp7li7piBbTWnJ98=; b=KYtdnDXiQaRnKJ9eb98BnsnQx/tg7iTwqStAs+4LOCVuFjsog2VSuR+2P2AwUSWtjdAqmECPATtx8I/NWWbbFU1tmGavZQKfKjaLhhKeggCQSRqJ4BARj0LGAFJICqBpYku6nKGl0976/AI/k3aYBGVhT1LXyXYV5vL68LVkQ6nfQuZPhOVnNEpo+Bv79rbX4EZ03kqpLIpTaqvJwFrB9KZmrk9uZ7+e9Duo/ypvKqFApgqG7DHsFET221fTOfPng0LyNSsdIoyC1KtJVTPMo819spBEd5Cmv69tDvuLPGyzORKxbVmRpQrEIwZyzPZYh0DnG0LTq3fe23zryhGNAQ== 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 DBBPR04MB7788.eurprd04.prod.outlook.com (2603:10a6:10:1e4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27; Tue, 15 Oct 2024 22:08:21 +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.8069.016; Tue, 15 Oct 2024 22:08:21 +0000 From: Frank Li Date: Tue, 15 Oct 2024 18:07:19 -0400 Subject: [PATCH v3 6/6] tools: PCI: Add 'B' option for test doorbell Message-Id: <20241015-ep-msi-v3-6-cedc89a16c1a@nxp.com> References: <20241015-ep-msi-v3-0-cedc89a16c1a@nxp.com> In-Reply-To: <20241015-ep-msi-v3-0-cedc89a16c1a@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1729030073; l=1769; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=oLfeRG2JJa/EVak0ZqRbgfNgEQ6xhDK04ybgk4QBnh0=; b=ggtUqSjG0x79ltLdbRziV+1fQMtLGonP7mytNXC8zbANXa9FirOFw5AzTBQStHed8I7eXFU4x 3OLE48THL6dDKyaXkJxOOuEoKxuWLFFdAQrxKVHBU+4XNxPUlWck2K4 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0059.namprd13.prod.outlook.com (2603:10b6:a03:2c2::34) 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_|DBBPR04MB7788:EE_ X-MS-Office365-Filtering-Correlation-Id: c910bd8f-30d0-47f0-522d-08dced65e172 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?N4xFQoYLAJLtlFQHhOSmIcMEjlIIsnz?= =?utf-8?q?ObEzfHnq8WKE69BWSviz7dbeXpwmrZKyEOI3ezMDcXt+uiTpQpfkhxExJYQifg1zj?= =?utf-8?q?MVFf31/nqNuNdeO19TV+MtJZrslC89pEj9jW45esyvSwz9g/eRaYELHBh5X/Kp6B7?= =?utf-8?q?64pxuyCDqRFZ6jmbLj41EnbQuPFq7QEWKd/wfeyuXBXRxLBkJ3u1eFm2G7Vu55LAs?= =?utf-8?q?GjzqfnH5hPAqyWMQjuzYnqG8rwKmbQ7kxHk84iS73H8lq28s2vjyDpJRQNyaknHpe?= =?utf-8?q?MHoZ+6kk4M+tcKWkzrHquM/yA6EkENgRGWz2lqonj5C7335Q3UWDrp9qQmrPBmAlj?= =?utf-8?q?Ljce3uqusIXnPEL+274UMNkR8AdmdmumHCOxoq1ymE2mYNTcMYS3Ff3YHT32Vw1md?= =?utf-8?q?S/olaIsSwZLIXnPDPiqwGwyugmaK6Y7Bq0y7ihBpLOucsP2Ani8oJtJPGS9s2OSLB?= =?utf-8?q?ZJDmtMaq22n28yZ9672CGBw3vfataDstmsXq1BpIuAZvq/Fgae8ixIT+zMJidfbKe?= =?utf-8?q?0lskRnPlCxmmbWQTkLacOP5jzdVprgO8qShoRfr5mr02BFPrfeaHsbJsoeey/DzNk?= =?utf-8?q?qfp/ocs9EzlkTUb/IjV21+pC1fuR330o2zxxABPyDLFe+xduM/idl7xeRALAW52fR?= =?utf-8?q?yjB1CQ9+QccCPl3oR7BQaHnHiCCD4XeEzX/M4LB5Kovtn8wytPkY95p+H4zwbEkUc?= =?utf-8?q?0sZM+M4pDPx2j3z3PkxQ+C1jWq7QkxVekTX0ZECozja+XhRbtv2yonDU6QVTVNPW4?= =?utf-8?q?iaLdVET+oHhNLqP4inqYe+jflrzTSOODIfx94yJfLg2RpscOFGjGR42munB8fhMIZ?= =?utf-8?q?ob9WrDyehQWlNnkQAHa4IaRsA6PdS3KnEVW9KddvDtE2kfZv+MK9/AvYrTd1tETpY?= =?utf-8?q?GOq5Yg9/wMmKVOZvSA3f07hqpp5d0GtLOdoaGGcq1OCU3RiLDfG66kskl0ZoJWXV5?= =?utf-8?q?fRWXf4MAB+bYi5B3tobEymyqH2IZDSIJBomYF7X6XMZYJ7zBG1ySXSyR4pahMV65U?= =?utf-8?q?JUn5t47Ja1aCu5cn3exXDlbKwSj1lKKRQZNLPI7zjQGkt4zx0MT7ZtNldCk6lb4sR?= =?utf-8?q?8XWcDdutdkaQVDugBvrFcsZV5BX9S7y5xRy5jk/P9bB44T5eY9sOlPZU7mbx+R2Oj?= =?utf-8?q?r2RvFTG0l/gslMEObfJJNxVKpSE5Y9nkmrm0bJhiEedU84uuYwgcP8xMCs5NBhRNC?= =?utf-8?q?n5U6RVW5iUO2vecXk6AEH7wEUi/LqFzawKNj+8iIyYhBcbrVH2But9X+jIz3TaQst?= =?utf-8?q?KkDNdcrJedeinuzYE+DS3uXbpiO4zUT1Huw=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)(7416014)(376014)(52116014)(366016)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?gpwmL/qlmCKXtVK0zoTbxobTWYsO?= =?utf-8?q?J8Se+Ur1UNOaDyIwlmfaiZINjs9Qkc7LObwYukzBvrYImBniRqFbzScwHCLoPw4N1?= =?utf-8?q?5lkN12pnL+flCrj9NHGonMV7ml97wE/S2SUzgszrbhjrlpeSOW161LY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?utf-8?q?qAUal7Hs8AORAkKoXcQ0Yl42KTKEQJbkGDsd0M+R2ECnEu2UWSZCICYcr2T2zUMxJ?= =?utf-8?q?54sdpcvOUiQlZlRGxrlhQZP/hwL4ua+5ptbkiSR4CDzos2BMYHdxfVrlyG9j/hesM?= =?utf-8?q?5c61ELSAyRrMd9QUhexzWRohhPqfIzZLgGMLxHz+XgJh2XMOr27CE9yqAjMoaxqdS?= =?utf-8?q?Zj+NnZrZ3pk8c6GMZQ+CkXBsfXUW/EMOmgru6iKLYkIGmjYpnmMbwZYsVdPT2rXMz?= =?utf-8?q?znv6HOz8Zf4z53FOfq3Crf2xLhN/jxDIGU4FgTJ+y6p0SQuUzmltzyrA0lLkR/N9h?= =?utf-8?q?6TkBJ5zhM0H3B8c9NUhHj1Ji9altRn7kMA/3fm6pZb+KLui7iJl73vXEzvNI08isn?= =?utf-8?q?YXSyjn/BNVgEJcrb/EzyB5IL79X76KZW4dHDYuBpoqEVjPz7DK3Ul1aGO+3ISP4FS?= =?utf-8?q?0OFeP/P2qRfsxNJMqLtuuMEHw6H81cxbu/Pl7a1G6nea1RWTfy/M42YY=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c910bd8f-30d0-47f0-522d-08dced65e172 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2024 22:08:21.0568 (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: AQhKV8F1fCrWYN3UEyX2/sm+pn1RkrqftuCWNcMDAkQqoIhbYRrQlocwHyFweNArQobKSIJNG/XEeAWtxYYAwA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7788 Add doorbell test support. Signed-off-by: Frank Li --- tools/pci/pcitest.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/pci/pcitest.c b/tools/pci/pcitest.c index 470258009ddc2..bbe26ebbfd945 100644 --- a/tools/pci/pcitest.c +++ b/tools/pci/pcitest.c @@ -34,6 +34,7 @@ struct pci_test { bool copy; unsigned long size; bool use_dma; + bool doorbell; }; static int run_test(struct pci_test *test) @@ -147,6 +148,15 @@ static int run_test(struct pci_test *test) fprintf(stdout, "%s\n", result[ret]); } + if (test->doorbell) { + ret = ioctl(fd, PCITEST_DOORBELL, 0); + fprintf(stdout, "Ringing doorbell on the EP\t\t"); + if (ret < 0) + fprintf(stdout, "TEST FAILED\n"); + else + fprintf(stdout, "%s\n", result[ret]); + } + fflush(stdout); close(fd); return (ret < 0) ? ret : 1 - ret; /* return 0 if test succeeded */ @@ -172,7 +182,7 @@ int main(int argc, char **argv) /* set default endpoint device */ test->device = "/dev/pci-endpoint-test.0"; - while ((c = getopt(argc, argv, "D:b:m:x:i:deIlhrwcs:")) != EOF) + while ((c = getopt(argc, argv, "D:b:m:x:i:BdeIlhrwcs:")) != EOF) switch (c) { case 'D': test->device = optarg; @@ -222,6 +232,9 @@ int main(int argc, char **argv) case 'd': test->use_dma = true; continue; + case 'B': + test->doorbell = true; + continue; case 'h': default: usage: @@ -241,6 +254,7 @@ int main(int argc, char **argv) "\t-w Write buffer test\n" "\t-c Copy buffer test\n" "\t-s Size of buffer {default: 100KB}\n" + "\t-B Doorbell test\n" "\t-h Print this help message\n", argv[0]); return -EINVAL;