From patchwork Wed Dec 18 23:08:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13914239 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2085.outbound.protection.outlook.com [40.107.21.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 011931FECB3; Wed, 18 Dec 2024 23:09:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563379; cv=fail; b=SMV8DJvj1++xveEsNvVJU614F3O3pHtzymYyMpalCeqmqWBPSNJuAvMYQDyRDJqd8CQRz8mnEeTUvpcHmZ3oM9++vAY/+WfeIaO7oTgdFsQndZ/uDiLbhBgSllSFLuQUv2o+JGwyu9QO02kcctT7EiCaBhjsc3B5OIkhka/z0LA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563379; c=relaxed/simple; bh=+tf6wudUoIbEsl/FZUMDaGOl5nvUQhr4hR8U75xWVfI=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=uG1fX3CsPHRKIQyxieJNFinmsNHgRo5nOday3EFYMOrlUJZ9YVPVXT2d6ra9VHdtX/6cQm1oHzz7dSFR+Kumr9K4WeZZwNa64Wpoj2aJ2SlMImGFBc5RQvNttP9IKx95PNmDK7GcCUxrsuhArrjUZVhGEI3KI1WIReRVAD42nLk= 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=TQvHSC6K; arc=fail smtp.client-ip=40.107.21.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="TQvHSC6K" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=psVHzcxMOXFsFoOaPAodoe/yzvVk0DWwy1PvrsUZpPISztU6hO22OezdKap/6gmH9WacZODU2t0nOYYmtH1xMR6g+jrPsLjsqQnQQX2wTrJztI9zjf7vOp0uvRyL9ektJ6GXn4t5BzgdY0jzpl0gnRrSPyf+qd3kwJbQyq6L0Gu0AAp3Qd9dqOROZeAAupKyiqqdrBI9sM6HsDjPv4qpuLq+KkegY76S6EWjTGoVC15Z6u01vLUy++43SNRDxOw78/l2MvVT9RDDnHxM/+I3B9TfjqbfVfSiGrRS3hYTiUYO/S4sgMueOIuqfQWdwvhjHUex6Zhn0Oe4y39FqEkTqA== 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=2EsQMPhR1nPrXLiGi6B1VPzpAgUnb47cDPExYl7k0lA=; b=iAagzOryysy0Me4sL+UvglvfyxjmFZ5bZJ9VrGLHIB/iunG98MJJ4NlVTKxqqWjXb0JMoRg3BEAxe9VG9RHYF2Txyd4C6OlAPToX6PAB9SJzKeo3maO3VCF5rtO9M8jbbEGpwqJwqxmxuvapcrWzOwLTQOlVm2Lc6kFs3JgVYGuV3J7fQPta095KwjHSj/gO+bWkVYkU9NgiOS+IwHwSfpsaGwp8zkI/qEjktTkbzFQZAY1vB1K21kopDX3C43QtmPcTWYFKmLlafMT2UT1OLAAZt7jevIbq2tzIaQSFUz+b0k2EW+PZimpXQYwwhJv0kRwH912nnCeYH9mBYqVYqg== 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=2EsQMPhR1nPrXLiGi6B1VPzpAgUnb47cDPExYl7k0lA=; b=TQvHSC6KNLGS12PopZgoWkkNMY1/l4cegWywpUgUXTAEKpZUMl2/zyjMk5YPGe0zzF56i8xaqsvE5Nz5FpMw3yjHUNIn2q7XPGzbBmPw+D5b4/KMSyL9kG7rFPd8leFSHXn2L7q3eCsytWvQwd2ow+8ny5QV1klsAC0T2WFFVf1IOt+C8veLEuXmD4yt09Cu2sYLNK/7S2v3rHcDOqRYtOzfMGkgdAnWis3fyl91m3V/eKgI1GjGQ9T/HvARuycdZ2tkHnyykNNfYdOQBtmw4EhAqQIKryat2NPXmV3bXcswfOyhgEpEXpI0QpSXM7ng9TtdqAzGaOo6wGvSAqrMJA== 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 DB9PR04MB9939.eurprd04.prod.outlook.com (2603:10a6:10:4c4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.22; Wed, 18 Dec 2024 23:09: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.8272.005; Wed, 18 Dec 2024 23:09:34 +0000 From: Frank Li Date: Wed, 18 Dec 2024 18:08:42 -0500 Subject: [PATCH v13 7/9] PCI: endpoint: pci-epf-test: Add doorbell test support Message-Id: <20241218-ep-msi-v13-7-646e2192dc24@nxp.com> References: <20241218-ep-msi-v13-0-646e2192dc24@nxp.com> In-Reply-To: <20241218-ep-msi-v13-0-646e2192dc24@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=1734563338; l=7892; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=+tf6wudUoIbEsl/FZUMDaGOl5nvUQhr4hR8U75xWVfI=; b=npYniliL17rb38kwx/P4jIuV8n0K8bEGquKoLUhFzPbCPZ29imQcvss7wSPWZNXcEAOJ2U+EA ja0KUdLbalnCGf/F2xFERIfVhzWAWL8Arb6S1T1ABVXbXLUWTX1Twkl X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0075.namprd13.prod.outlook.com (2603:10b6:a03:2c4::20) 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_|DB9PR04MB9939:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e51f7d8-6d3a-47e9-4c8d-08dd1fb9095b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016|52116014|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?7pcgq3x9RGqSnryvYVhc+zxkydYfWps?= =?utf-8?q?PrefJQ9HEXH8KweQUbQkm08AxnE2lia5PFxG4J7WJjUkpBJd96eRMjyHoYD8gTEXh?= =?utf-8?q?mtcC7/WbcYav4ZivBoVtYiib0eIe1ffTYWKlY8OKxriDZCg7Dd0zmNlsrTgbAT4Pn?= =?utf-8?q?e+++LNCRV4FY6kb6MXb8MINDyDj3EGBaT1H4wsmvAfS5nypq8yEMqguWQf9ORhEEk?= =?utf-8?q?p3x3fz205WRX6LiJRILzGqQWgZvRLF3BU2IulNXjLhUEcPIpPS/z/tahCq2FYHs1k?= =?utf-8?q?PhN1sxnvAX4IVFZFvhvsLey9emtQKxfPYnlBvfAy2tKCA6JjhTlCPCQKtAaJxQ50S?= =?utf-8?q?2dOL3N9sWPQsSRs7YSnf6jOgSl4S6SuSlp2g9WBL6bco9nvlnLNMLfn4/jNtSmyZV?= =?utf-8?q?n6MN5FaJWh0+mazd4Bo1O/Shw2gynDHBFUz5DHnrHgfD2GnaogLX4zyZBYxHrs3nM?= =?utf-8?q?7nE6ROt7UO1477PIvHWFIIS1NN8XZgVJb1d3dJ+kZvg2MCoO3LRXOGq+MaD5nKHRt?= =?utf-8?q?409H7GydQ9DqdsAl8mLZp0c5Q8Blwb1hEBzUTY32bsnPBPYQHm2iOWH1n7tXffoH8?= =?utf-8?q?WvWF3ItxcRyHHQ5Ljj9krFlMAyrJfqhHofbT5JCo8pAJudxSePazxyeW4YFf7lvwY?= =?utf-8?q?CLrAuD8Vst1ctzynzpmREG+GrDrkLYyiWUP0SWD0kaxCl7e3QkWjPTRlaLM5JXKag?= =?utf-8?q?Qkak79NdoIKh73oZ2e0WISzt4AD2CImOcby1D5tyFFNxsW7XY7PflS8NbXzF+GNVN?= =?utf-8?q?QwVfc/GhFfHoMm8AOhIhblFET2epkwdOH95dePZ9pY3NU8wej31ajuFbAxtNLsYpY?= =?utf-8?q?4V2d1vXFFjMa+uUA3g0npzEHU1p4wnj99ho0AWrNZorI1JbymzuOdP8SbDomH7k1h?= =?utf-8?q?mXG5Nz8TewhGOYxG5+lEvasZH2kejbGOZGGNp+TkBoHXRcTCv8s3EAqHH0TZSqmtm?= =?utf-8?q?xH0ObKvvYSCRKjXS64NPyUtOTRQA0F3BnGvD5Ls/da4sqcijT2Bjqr4ldfpuJIWcy?= =?utf-8?q?5GxnvokSkdEV4qwk1rlYwSLcCw0s3mxNC2SDa3JozhbS8p1u6euRPJle23Tlmf4gN?= =?utf-8?q?BvCdOioIn2mNkeEJuhxcBMh15hJiLcMyIpGYX17BrCLmiN4kL4v64TAjDSfGNhcWi?= =?utf-8?q?aHGHatlMkPLIPbMVlt64xy+/2oVpWoKT22h7V0pivB/oJsJj4OpoZn4cidi3SkVDf?= =?utf-8?q?XMQOQ9MOsw2vlzU1C+MRC+jqk/8YdfwF1EPGCM5EfrT6uHmR2XDq5SgBIpeFFVtYN?= =?utf-8?q?B/sKEjflIXnGDXvOotkjs+XmYNcBhKbEcdP988HAhNXypw4d+izJjPxyl4ZO1iAsg?= =?utf-8?q?st/B6O4JbFTGQgD1QDJsOQSBbuwBhM9yWehTswYp7uGlnloPVHqd1/DPqXVXJfN1t?= =?utf-8?q?rki9tKbthmyGdWX0G3LmVv/s4oUCt4r8g=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)(376014)(7416014)(1800799024)(366016)(52116014)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?+V4mIw/UwwNqKZvZoUzRwT0oVANz?= =?utf-8?q?m9/oWL6DyI2Qw35SQQbH6YIuYNA4ArnPXQt+ew6aGrMDgFDJt/duyDAvXlI2M4Js0?= =?utf-8?q?cbwF85qGHKUd3V1nqKhxfcp3Lqi1IGigehZsL6JbaSKx4eh5tczZuG+Ba14QOpBDx?= =?utf-8?q?JqbGHM3HZfgq30y22048shmlZDGSZNvzgafrW8Wavt+mwSd4IxNUjuSAHIQf6eTC+?= =?utf-8?q?wwmfERQZnKWsgDjpr8RBUb6MQTIAE2/HMlb67ZVjLYO+h1c+r95U8BXndUDv9MIO2?= =?utf-8?q?lqfNmHrP71USa6t08EZI8pkLxm7deFR6nEB4kYIgVhlQrAk6MzIjMHkBiYoFD9m5o?= =?utf-8?q?uWTXOXZPWPApvydmc1pZEHAoQGVyvF0s3I3dPrxJubebXF04W1uMrr4v+k49cVO+M?= =?utf-8?q?Qj9HtequIkRE4yheAien7Z5mNwul1NcOhA1gRgiaC6jhUP11ZHJ31WIr+Ag72Z5sM?= =?utf-8?q?33um5lgFh/ree91+aFktjYuRRZDneS26HWGPAd019oiFWJ/ZIEES2Rq/CF2B/zmB5?= =?utf-8?q?+zywIQVuTX5kqr5kmxLaPAxR+2OFvcJWInZjYQzKoUxbw1+oTqRMABOJkJ9vFEO01?= =?utf-8?q?yaUl5O/KcoorHl73S0XkROOCrcP1y4w9MkNfNtq6YWvzkAGhg7EgbQ3OsCX3rJRon?= =?utf-8?q?V3snl0/k9yegENPAv0m2EukRahTniGmMJ4auE/DSc6QB/0QZCP8Q+DWzuwzGg0Dun?= =?utf-8?q?cvZoyqv1WrvQDdNyeyCcxp2w6SimbDpC4kGNetdYe786/ZzR//Pik/Jgk6ju5umYr?= =?utf-8?q?KZzm9k4ovoV6XCqXakgWC6LsndZgqZbzoAnsR0lw9lS2BOSRQtnCV6Ilez9S5YeZR?= =?utf-8?q?TAYu5hRrrgh8K1TD6m94J2nLiyE7kuK86ovFZ/dMzGNaXpbE3JpjSRZ8PrpTaiG4k?= =?utf-8?q?HOj6WQdwwzU7BZAni9mDEu1/hvoWpIGlrRXgHle2fKtTyp9zZUimvLYckAncnafPT?= =?utf-8?q?A1T0XTUE/TDQrZqmBCcVz90+jQu0kdDYNva3XG5eIqAAobq/9oDvZH6sUAQwYCzUF?= =?utf-8?q?rqktx3tyutbvjBLLG4ezC8F5AX2PyPEWuBb4KYS9y9Yov4LCOWxidFFrXfvLvQgf/?= =?utf-8?q?Ul7YWimy9VzkHx+4UtFPHyDampsBYmAmIfmt8ixriEZeDcplJuDdbxa3e4QASyKMp?= =?utf-8?q?0Ie9m7sp6AfQT5rE4K1DcQF+voEO36m4UggtQdFqAq47NtLUYU/zHcEHFh/9nU3gn?= =?utf-8?q?5wUukSvRVMWFueLlmqJ4VENO30Q0OoXxHb6ic40YHKN0/r1WmB7wLatyiDDty04b+?= =?utf-8?q?PrDOaaD9FlGUqpH6iaXSV5kX/DqmpIfjBFYJrrRSBfaGGFlLuwY3otxTHVfQs1Obl?= =?utf-8?q?D4VB8Da0w1mqklUvcmHS0fSM8FNy/79aX3IsqsYNZLLitRTT/4x0LBwHPsmYJzKHj?= =?utf-8?q?55WXewQghwQzZqA3qC88AjKZzRMuNA+eyrXnwcZQbMlIcyfR3j6kFOXelXZjWUDOs?= =?utf-8?q?zzXZgw2dULasqPrEOvEV7/OMilxrrHaN+U2hxPrLX62Tb+qbIfH3zZ9dIuUOzD8W8?= =?utf-8?q?ra/6e/TQkay8?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e51f7d8-6d3a-47e9-4c8d-08dd1fb9095b X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Dec 2024 23:09:34.3649 (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: g3D0I/rG6j6tZfedXqxto7EeETXsGKE+mfn53kxbH+PiT75NYhOTV4UcR1UXwm78wYbuGf+TP67lI69XWST28g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9939 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 v9 to v13 - none 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); }