From patchwork Mon Dec 9 17:48: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: 13900154 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2076.outbound.protection.outlook.com [40.107.247.76]) (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 26C901F0E34 for ; Mon, 9 Dec 2024 17:49:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.247.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733766544; cv=fail; b=ANfbu3PT0IhYRF/reaNpIkUbgq8TWLerKvjctEsEuatvQ+xK9R4xOMMV63HprPYeg7+n4n6Gpuu7KKbFKlrrFw1IGAry2JUrW4UjdNHi4kxqnz0zmSdUmwnEq2Luaei96abw+FYKf+NFsIdP1zcDStFzFLTTsmn6SEyR/2mZDlM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733766544; c=relaxed/simple; bh=PaYILZ+ZM1f1lH5TRWB+Pf5dVKwn8b6IHDryYNsxWvI=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=iZaNV2Va3giI6qYHMHbIDYSmte+13xLwakcSckwdHDlSO4YfucXkU7qqypeRdo18fzrH/Lqy4Z2Hn7QG56DH4rxG/ykdrM0MZch/0C9yDb9i1Q1HXVpaBzw7wIkTmQXg4Jz6XU3wQdMFhtNW15oamhZVxfq75SJPwoS9a5KqZ14= 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=PsMwRGOk; arc=fail smtp.client-ip=40.107.247.76 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="PsMwRGOk" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Gts5lNCnXEkR1dUU9G9136D7OELkg0V0yYB8mxZEz6lllMqHYRZoNnbX1ucN3Ok2YBKfy5oRz3zdaF5wLZYGIE4E34Ii7vmDLdB9JBI93GO+NtPQGRimdLQbR1VYHkhie3/JO5lYb9N+W9AfXqYRIqnEXzbK/1TGWrlgZmz5J9wyjhTbgJtwJNSq8N/vKxnY2VvKMXnPC3pEetirKdPBL7F01ptpQZSSMdMFYC6bQuuwG7hNNYqfQtBs7NPS6aqsojn8FCONn1R0SoGsNqS9wHxtz/SshLbNyN7KeXj1iqqOmob9r97khk2znDfbpheS9Fr5287KIYthqKCh9oVJdg== 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=K5FPaZ3LayiFO3rfW5JsISxtSjCShLWFdWQKWv27vnM=; b=Tk88tRihZB0txaf2OpQO+0pAjg20iZd+Qu5yYJil7wJW3c99nz7+yTJRBImqebwJZqUZGvOB/iRd0D+mGWqDpSzzdMkhepjwTv23kKeTyTxG05VnDeWo8ALEb14qmW4fuACq85ONszbB0Ow9+AtZgHbtH8Vd+9XGSreLPLLhbR7YiR9dwWa8dsIGENkKurB9CVfrZE6eDLVpULBFkl3nPcraea/7ITZnqhDT4DLI4tGCSeiy617Pok0OsyXkqANjRRjkSSBp7VV7USAq6Y3kHsJHQbn9oB05g2iQZC/cn1PuFX41GhQcEgA597yrbx2NDHEl9E3B7xF8UppkFDpjaQ== 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=K5FPaZ3LayiFO3rfW5JsISxtSjCShLWFdWQKWv27vnM=; b=PsMwRGOkTaukH1ZMQFe96M8LsQ3NQTwx34wJozrD9pmYYRNVYGQqBo2SxD53jGDbmKxgkzamT6JxrCVz/7XYJGNP/fMd425BmqOSjR5aO+Bb1gziLTvUdcjQmvvgu2auTp5fy6PSRXvBelBWyog1KSsv4aK1Sb+lH1/H2G+rFfZxOgIQ6JiUkberEDPlTUe2YfJeufcJ8tSil1fss6ri4FFj6niAXqAcbXeY6c2khDAzzDKI+QKAoe4qk9/TmLP4hzd3vV2FRoqbauWnWCFc3FSDILHpohwkqeDWtaZoXwtXixJIlBOaYt/u7Qt7Id1vQoh2cqDRvTJRRxYf7+tmxQ== 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 GVXPR04MB11017.eurprd04.prod.outlook.com (2603:10a6:150:21c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Mon, 9 Dec 2024 17:49:00 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.8230.010; Mon, 9 Dec 2024 17:49:00 +0000 From: Frank Li Date: Mon, 09 Dec 2024 12:48:19 -0500 Subject: [PATCH v11 6/7] misc: pci_endpoint_test: Add doorbell test case Message-Id: <20241209-ep-msi-v11-6-7434fa8397bd@nxp.com> References: <20241209-ep-msi-v11-0-7434fa8397bd@nxp.com> In-Reply-To: <20241209-ep-msi-v11-0-7434fa8397bd@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 , Marc Zyngier Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, jdmason@kudzu.us, linux-arm-kernel@lists.infradead.org, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1733766511; l=5981; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=PaYILZ+ZM1f1lH5TRWB+Pf5dVKwn8b6IHDryYNsxWvI=; b=6YkXa9efyhaPyEHdEfk/UPRrGP1U4en1a2QrC7PsgIw0Z/YNaRO82kfvV9ikJWCZk3sY4N0+D Vxp0bukLLIQBv5UpWDaMZvCtPkstjtAlQLWTqRtZSkFqO+Dbk9xmCJ6 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY5PR17CA0070.namprd17.prod.outlook.com (2603:10b6:a03:167::47) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|GVXPR04MB11017:EE_ X-MS-Office365-Filtering-Correlation-Id: 93ef8d64-4353-47c9-4ed5-08dd1879c379 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|366016|1800799024|7416014|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?KqgcC1mASV/ohKM24knHfl0+WHKEH+p?= =?utf-8?q?gQaEK0/q5euRSnhNZLKiIfFSUftNIR8pkgYMB1yGTa2M10HkiQzMesd6dsevYck2N?= =?utf-8?q?V6BN8VTZLFt3a3G92XO+MB0yzz+k8Lhf9wj4Y6crVibrG520thpJjMmjY0/JxlnxC?= =?utf-8?q?unLGZigLR5vfJVAUsB2fk5HaCsCxCVE5zWu3mJwzf0Ozyy9alt2xjwhQUNANMwcCy?= =?utf-8?q?mvNbNin7pBVwQqb5jeJPEpn5Ww+vYNbQP+Q90jaLZ3lOk9RZHGzGIrkvUd9UsSryd?= =?utf-8?q?xLoyP4TcStEMD5fRNlqot0eLOOZygONfC1jxu5Ddr0s71r16LsEATRssIR4lWElV8?= =?utf-8?q?rQzjV1x07GLU3E3i7IMFJTJTFkOQ1IU20bBIFpak+FxbExqMRw5yOEv/QeXbQJoP+?= =?utf-8?q?3UB7IUVLOccRnC1fkzkSq8VCYvdsjKYRi7yV38ghWNYGMD+mKOLnumlV6TKQosxy+?= =?utf-8?q?0FxOa8qO+c0LDkkiTT9T+Y23M2srRidkuBZFJymFeJUMvIIFasl+Ae3tqyUahzmx8?= =?utf-8?q?XgGXG2LaprZXxCF0WUS0hcE13BdzRV42dliZDRJgWbgzekVDGcyFkCL8P1G4ErHmB?= =?utf-8?q?Fqt/PthPtzUuvjXHEABm8rfpZ8DVSicxH7FPfCukKjwMZmLpL3nlk+ks2Ebp4WRyL?= =?utf-8?q?L9Qkz/6EVmKAU/dytdPgznKw7z0e7QjdvMByhLzq1PhuRrYB2TRxpdvS02XfrTAhy?= =?utf-8?q?Qei9Ui5BDxWxSof6nMzAwMtbhFSFR9cTPymNZheG4XXnSeZEW5yEFmsSW/gqMbbP/?= =?utf-8?q?7SYDnBbDXGIaackAxOnoZhXpqdWIKBN9NashBFMAFFYu7Xd37/ID+0EiV3lOdR+9i?= =?utf-8?q?2kCs92HQFoI9h0Jv8MGmmteiKq5eZs0d8Zo0U4YJJKL++B80JJ/fkqM8Ris39rBvQ?= =?utf-8?q?Um+YA2u4HG/72pNP7kWX18wPi/AwupR+jDc+DY6hvuA7/qKlVoldRWnY+UX/QYaQn?= =?utf-8?q?BzBK6TPqb/ejy9InAU6DLpRlKEUJpMrFQbklM79uyTO5OGjVLOlVj95lzKgS2mkdO?= =?utf-8?q?3YEXp1D4J2QrdqtxoFDc/DyWsEn47IiROPlT+DTN/8j7jo3ImOZE5ptmwPzTqaRtF?= =?utf-8?q?IFPGSP3o1tXwsAN0DCpxnpYxxQ0CQYSVJF3i2owXFgxcfpEqwy00Kfg4mdyyj9yeB?= =?utf-8?q?MeO6c3laTW3KS4uX147kaQ3GrgBW3HQ8bE39Qo5duv+nWS5vZh5lTmyW/JkpLAxvI?= =?utf-8?q?Y517dooQzdzVVn5Z+w3zAXywbq1+CCjti1+mH67HCuAsausSGpTVDuchZCZ3AnbfN?= =?utf-8?q?Kt8daeUZ8Rl5MvU5mBeMvX9SLaCyLcy5DFJVTWtpbL38YlLKDezq1X9nhZbE9fgMi?= =?utf-8?q?KJ3503SqdFJWXq/69hH1b7jwOn5Pp/TISXbeuDDFvgbODnX+2cSbpaI=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)(52116014)(376014)(366016)(1800799024)(7416014)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?CcknR9huH6K73J5SiAKVzjYJHoG7?= =?utf-8?q?BdbYiCldsYvpvQwdk/N34TsN5EWR6056Dte2s8hieDZeVyijTn7WMW5HansYiYZit?= =?utf-8?q?ttKioJzEsYrtnSVd2YjB+x0tydxFq+ssYKR1gqhImGNONYBdMsHHWGmtaA6KwXchQ?= =?utf-8?q?Sx0IynvdkFAKjkTh+2oAy58kZa3EyDb8gDd/TnXqCEQ2eePe+bUTUYHd/C8E5Q2Ql?= =?utf-8?q?QIFmjzWreksUG7wqHfS66kQOZnwS2qPxXJL6cOBl1lkyx7nE59xuCNE2cqw55iZ3X?= =?utf-8?q?x4oa/tmUhEaHxyvAh3zkKa8TCRE8UmpHMui2Oa+D6LM50Spq4pKRNLSZaenvC6W0O?= =?utf-8?q?XSzvUzw4a1eSgqskG1lzmo5O+gskoeRfijYF7MXdZrLdWTLlCgbjGTsTHQe9Fmfgr?= =?utf-8?q?iCrtIYC3mFEhdmPULdmL0zROHZLCYVi9lnFRm2lt8C+TW0d6ma6g6/7F8ggQt6RE4?= =?utf-8?q?oT7k8y7XP5Zg3O21eUXLPmWxnKttktjGtswJ+SYSRMLHieC7kFJ56FbmBeug2kj7v?= =?utf-8?q?50JnfUGRcEaGg31JUi5T7VguVDS0NQI2RZtQ8NTJsoMwYTLP3+mjZ8LpspT1w6g4f?= =?utf-8?q?LcZBfBESUtIM2/Uj1yKRSkQ+g0SZqU4tJZ+ye/DIadTUH+UjaB+P/8BdORRjSPwj+?= =?utf-8?q?9VdbgyNoexmqf19UTqHCW0n2ydxE+L/ehYRzb5LC/Fru8436wqp/TpfHVZ7UEO3yr?= =?utf-8?q?gw2K8dz6jI4tE+FlCuQPx73ceH1IG/KSGidFnY93Z8rMKaNFQRV+Az0+cFvXTpReJ?= =?utf-8?q?OtCAi5SJfkfOCxopv+TyBRrQn4Ldn0Tw3zw/5LV/yTDheTy+STVJGi6OWza4zq7uV?= =?utf-8?q?dZODTS6D6D39sK3sbDFLVkZQbe71/aC13eJMlKKtcDR8fVS059u3afzI2kV/o6wHS?= =?utf-8?q?XdRppadulzyifRKQexiK1Mm55td5rKk/KfazIrB/CRCfs/U50+H8oend+aJ0NUapC?= =?utf-8?q?d54kgbRGny0pnuMERCtFWfHIJhTws1YYj4qCFNJG0aDwzkieCvKKWTQ3ujHg6LtCN?= =?utf-8?q?28NlA1YZpJDSf5DlfZDehyJiJ5CATijP60ln3AtQplXnD5hu9YPS/SE+yh68hbpI7?= =?utf-8?q?+9S8izcZQBQDpNx8Md4Sk5PJz0DPOMUguP9+i4iJVB1Rl4QKpAT8fi/62N0Rcqq5y?= =?utf-8?q?CCd2zjdgYbfE7isE4HDA/qbFxK/iDfpZ6z1lSNiKjVMZb3rDHHSFnyFqI3qsq9v4d?= =?utf-8?q?/pwKGapssPV7Z6Tw+MMBRXebb1sT3dvu/UKJSMeADQv2zZF0AGMe9y+I8+ORwHXKJ?= =?utf-8?q?I1fbxXMZBCKFDsBp+Kk6+b8h1nnjJR0Oz5O1M3RlunHDc3lxkSEEUd3hCafZ7fIRh?= =?utf-8?q?ymZsejG2xitj7ntUR1SRtpM4EXV8Wm8he+GfUEzZKx7/okcYettkK77dgEHrN2gNG?= =?utf-8?q?G78+paoZnb5veLAtLEb10y93r36BSHKurFU6USCBlTnGU9o4+LogS+MV1Ui3bO+7n?= =?utf-8?q?UdMDiCwikfqhHTv3l1PocZKJ0JI1l8iwwS5I2HxID78GgkKszisOfu1tJCRLhofGm?= =?utf-8?q?44AcRwOmdS+e?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 93ef8d64-4353-47c9-4ed5-08dd1879c379 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2024 17:49:00.7013 (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: jzosXSegx4n4avDop9h0qMf9tGQZphrbd1JEZ56yoRfkWTPSPQs+5KhI483cHerdfwQBY31y3NPZpv0J3EMWwA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB11017 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 v9 to v11 - none 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