From patchwork Tue Dec 3 20:36:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13892940 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2067.outbound.protection.outlook.com [40.107.241.67]) (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 90C681F12FF for ; Tue, 3 Dec 2024 20:37:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.241.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733258250; cv=fail; b=eN89k+avbcwFKesfp3nxgtSLYaAf+NGcoQnpwu8KalEwmAmNMS220mZFKZEgcJpbiqLF4/Dzi0iUXFxbkaMZQbX+mbAdKJQYwBazszOZf7fH/m2Ea1L5umm2mYrjIUZXpp7NX2sE3RlDWECZpZ8cdK+t3mQMvmVmyyKIbQqdE6E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733258250; c=relaxed/simple; bh=TLSUdRmp4K+Pa1tSim9uHX8V2yONts3GeTemgjKsAlk=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=QJ7KFb8aXw9hONvxknv7OMh/VtJneDOVPtgdXORIocMIR2mI+gjYzj3+BjvpE1JlPgWNChG/EJXcDlXRD9hg8lNRSTsBoLWDLHI5TUZ6GT9uX9C2ioMWQPe0I6KpuR8+69F853ZANFLdWCIybT81FYMfuudHfZEtOWgOumb8vnE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=kHBZnV+k; arc=fail smtp.client-ip=40.107.241.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="kHBZnV+k" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YTBR2zM/WYLBYoQ0AxXjiDIqa/Nv9MjxSP+pAwn0l3lBvQtVcTWCzE87EN6F+5pZ7oAKxrARC2enQGsDKyDKFGWowPjHPff2t6uPLnt7fo8LBEBw42LfIbqzrWnMDdza2iggmr9KHAV4Mjmk5RjeTGdFSoo4YX/dPg0ekcv4gH1/7O6PtHQ4lEIwKgl9ri4MG7OrdxqW2REt+7mIk40AFk8SwjBAKplQ2jdO7OkWsJOmEP0QEtd/eQlCB9QvHNMW1mD3JNZNDNqqxOFbSXLQf0DtPn4J1GLE8NZnwQot7t3K8H5lok+bMHufUEJyfNj4EI3lmynrzCUQbEmbF2nQXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BeYMnHiz9JJVFA6A4TlHysF/6enoLKYcE6EAntXbX1k=; b=Ba5fCSQix67hBOHWWggRt1dFTJuXl1l2y6MIDzKpb+mLE66gfZNProHVj0EZUahlfT3nLevqbatbQuRl6j/y5cpyyiGSiQNwJgA5EeTOHYss8zUTs15s+1vHyB8BI1tWCpEf+u2MJVI9ZPQDCU5Phk7Ws/wLhLjrs639aT5PzGbsDDdqwYezf6tR9pe9F7eDZkMtlYSpRgSUwSNpAUhZBOwtPIf2lW0mYR3iGq7dI6nr715Ayq8QApzMYn0LAg+ChdJDQzFdpN+HLAFJCWpbT68iy9nof2rDlvjUX8tE7Ycz9f+x2Tuk0zzMlQMpJEYZcIa50uq+XEowJm/LqJRalQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BeYMnHiz9JJVFA6A4TlHysF/6enoLKYcE6EAntXbX1k=; b=kHBZnV+kxcexcNBrrku4DSUUz+dZhpiiZHLyLdLi2nJkzZ6Qr8s2zJV3dNBgg/Zb06M4o7fY/Dhtw1C/uFfNY7dL8D2VVAAsizcsuQ4annATAnC3bIyyLCuj780v0YG5vMPAbOoCCLoRcs229pIiTLKvBPzz1EDe/RnmMVFNh+xxRSRJn3BUt+dQDs6eZsRpIUvI3WDRnQeByex6V5M11ks2GuXYcEZqdKoNeSLu2fIo9btjPsf5L3UJEW37/Z/DMKuM4+nrJGyZUg7EfX8+R/6mc6w6H9JuzcGuGe5/kny326E3PTdE+IpaCFz+djtOXmaAd3af8fB7xbawYhhIJg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by AM0PR04MB7108.eurprd04.prod.outlook.com (2603:10a6:208:19e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.17; Tue, 3 Dec 2024 20:37:26 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.8207.017; Tue, 3 Dec 2024 20:37:26 +0000 From: Frank Li Date: Tue, 03 Dec 2024 15:36:53 -0500 Subject: [PATCH v9 4/6] PCI: endpoint: pci-epf-test: Add doorbell test support Message-Id: <20241203-ep-msi-v9-4-a60dbc3f15dd@nxp.com> References: <20241203-ep-msi-v9-0-a60dbc3f15dd@nxp.com> In-Reply-To: <20241203-ep-msi-v9-0-a60dbc3f15dd@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman , "Rafael J. Wysocki" , Thomas Gleixner , Anup Patel Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1733258225; l=7859; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=TLSUdRmp4K+Pa1tSim9uHX8V2yONts3GeTemgjKsAlk=; b=fGJEtd0+B/foHLN/kaRCLNRuEb09muUN2U21JQ2RerUDLlgi7xhumj5uX8/NHnlGz8zNKDQqk qsH9pBQGMKVBkSo5AjLO1f2NRcgcfn3x3fomPOurttl8+eoQP4Kx7Qn X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR05CA0013.namprd05.prod.outlook.com (2603:10b6:a03:c0::26) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM0PR04MB7108:EE_ X-MS-Office365-Filtering-Correlation-Id: 5d8f2714-f677-4fbe-21ff-08dd13da4c64 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|52116014|7416014|376014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?8hnAQ1QdY+YW7KYWgKLTlduaoBrdprN?= =?utf-8?q?VhDePCIiyPxoau+zC3Z9ILwLOexgD10rBZBuYXqzkLhUCtvdCki6DUj5AvYL8/uDK?= =?utf-8?q?v3UNj33MRcxUbkl8lwqOMs5UEJdxCglwGlRLdDDpPEiWnsZb9dyzuGVMjNgCKml4g?= =?utf-8?q?wo2uHM6J/UWHgceUf6NZDDVcu/S1k9dWCoLSt+t+urOE86wA8/MpfdjQoOdOE7Dii?= =?utf-8?q?iF9g+zjBn88mhc08rQMaQFTa8acSkJe1V81qtHSjvoLzpHUCtWICQPUMCGYNDWd7t?= =?utf-8?q?soMKlgSKJrWgQz8KokNEnV578OyFxVrvBHiSPAJlORoFkVifuI1UcjwevAq8W4rQA?= =?utf-8?q?6KQlHWc7RV2i8wdvsQmRM5rgFlc+vwaMxCQbfXiOhVdEz/N0yBqgj5OyY1D8qa7Nv?= =?utf-8?q?D/RhRatDTmehxgC1l1EYhnwkD39X9xQ68HkZiAo9HH5sjObs8NFj7rj2bIwLUu0z0?= =?utf-8?q?g98sqkgj5fXuMQyqa6Aw0MZIGXMsRriH22zMU78IN56Mzc3LXVao8GBH5Le98kkQX?= =?utf-8?q?MPWJNxsRX0fedWnlLDnltBx5Zox/29yuYTtjCcvoQExZKpqoK0qI62S0QT5bN7f7N?= =?utf-8?q?f8n+rzkqQcrldJmulKdBM7EoTwqV2GaVX/O8C/H0aFtxGV56ZO6wjxk6ZMsYdv12J?= =?utf-8?q?aYwVzpZUb+O0VY8RJtpzB+Dw3vfjlqLsIh/nZh2iY+MMC8M6Hzy99YOwPNZszbci6?= =?utf-8?q?vwzyTPmvP7zaHWgKNTWRicsSXNOYcYLgfKAGqVeHsZyfit0I46hVUays4OEopxm6z?= =?utf-8?q?oWS6Di0qo5Ff8/KU9zN0Sed+FxwByCIRwJdCJKC6FGvy33qD2J4DmWGgd7/7eZX6e?= =?utf-8?q?PNxDzWLi9fCezjjZMed2R3RoeZ+kqBObnXMDeRDB8WWwTjJHLRYEV7SKqSm1Ek/is?= =?utf-8?q?wHSigORf//9KCuhkkna033WjAmt4dIqEQbTaWGV0A2qiW4+uZcJ23KrgqRNvtjiXr?= =?utf-8?q?sgPGTQqz/PjhN6RjKHreC5mvZjeUyTNuTdUrOGu6Dw9HrC71TLXG9WiJ6HF7msV5Q?= =?utf-8?q?MMDK4m8iEs9ZmlJ34UFeAJ2NkRRozxF4o+FTBjgWoRpDXu6qVX5KalOy0lYq+Pe25?= =?utf-8?q?hFQlkXRTINMb9mve6q6eYooFnoGuAf7xGjuSRqotwNw0Etnj/0UOw8632MHrvnDp8?= =?utf-8?q?RE7NYYmYcXYO1HpaOBSBOWMhES0Co3BJGlcxjlPShB5c6xAwfj1aKl9NOdU6lpDeU?= =?utf-8?q?FGeY0Co6WNw/3xcD+CRS1g2W0EcTsLOJVcD8QFNDC43TmUzZAOz4BSa7XF+/UgmRz?= =?utf-8?q?/q8z56k2H1X1kwUeoWfagtwvZ1JRDiSJkI93l/Zi0BWIqSeathA3cTtdw5rNX9vbD?= =?utf-8?q?XDJuEBOFFZ1sZwPMn/YfCY/8Y0sZsYSHQA=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(52116014)(7416014)(376014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?jQh61wwVTBJODSf2Ynn7XTsRsRNa?= =?utf-8?q?IH2mrk251f1exMJf0J7nW45vXKKi5nR2vaBrJMQRpNqFRWkXAtQkNMr6TTpHiDOcX?= =?utf-8?q?01HGSkygaSdbLuvx81n6chPBtPwxq04uIgNk27eMNym9opSeq6DxF6FAUOybkGsjD?= =?utf-8?q?X/whdeRk/KOGAvqXKHIJv6QkXjpZ1bTuOGmvatKDbePJvjEUZ0DQVWY2vPdwVY5IU?= =?utf-8?q?juqWuwUN/5eFbv/MFXtO4SdZcQM0JJdS/KAepxNn2XDkYDd5QL2go34idVYEFKIm3?= =?utf-8?q?kQSBPXVIOXhYg2GdEFIK5pd93ZoRedhu792/SedG1Gum2u5cGbq+BWOfxIrkpL400?= =?utf-8?q?tqmm7VAI4AO/viKgg2wAFPL8KfiUBWUKcnYEgIG/BR4THOalCsJQXFrD7pk14dcRW?= =?utf-8?q?aJMRqjAIr+YfPNGSY//SKtJvNU4JVvDctohoJUQyGouMmH31Fqdp+H/4cHjdoLaDJ?= =?utf-8?q?CNWa2OI6KgRSaiAJSmuSPsP3FpO0uo9qWUmpeVtVp4xOQf58NtEnGwj4uzNIiIrdg?= =?utf-8?q?u70XtbRoQOOqBIdjWTxHt8SorYNTPGE/ikaGbFoLUoilRvae68QRPNJ3XxWf3xnrF?= =?utf-8?q?d3Xhe+xB6//SpolIkXTs39QJHTGU6xtCze/IuPkCQ3NAGQ1nVg4zuU7rVWCif55c8?= =?utf-8?q?NU3zBRd72S4dqcFsc7DnMAqeDVfrvvr7lWCvz+bbhgEYFqAPhWjDeRlLnGSiB+7JS?= =?utf-8?q?lCOq7qPuWE1xh1vE1VqWDmAtZHrFE336QsxHvLhgn4RDCGJ551HI70TjsNhhz3swr?= =?utf-8?q?XWWdNSpkIth/7BHWtCu+q0r4FLn/HNgd94BXIFRoSVbS1OIZTd559JVkqVgaqM2hn?= =?utf-8?q?3aCyJkGSnZ9pU6TMu66ofpR53ORN4j/sFqi0lKjdW+ew9IhX2lXIw59y5iBoSwCVw?= =?utf-8?q?3SEevxkmyPV8BDMA1ls6EdNahOxcK2+0IV0jFnk/xBPbowtW1IS19VYqOnxc9gL9w?= =?utf-8?q?SeLkEIuQuAu4QisDV8Mf9yaRPkwKyfiq7GIyXlk3ni9iANzO/t2/aAsy08LcSMEV6?= =?utf-8?q?rgiNDdHdbrtkD9Zem7iZB9/PO16OxYqjzKZx3XxG1QiXQKIrD1AeUgsv+sh1ugsFB?= =?utf-8?q?cRRArSCDeiWStIUo18CF4O2Y2lieoRAonuRNbSmqRt3MelNZLzAJnO/bkMOssGl/w?= =?utf-8?q?mkF4CIwm6zcnujVBq9quG+p55qF0s0P25NfkkudjnOT1N87+kVIaH91KgYrMtWYra?= =?utf-8?q?6jEKfyvgs1mcy33Ib6tvpExg6vOkZTjDkX8lhNib/wUkJsfqo1epMSEGUvsQnUZiL?= =?utf-8?q?nZFCaGxW+hskYfdMZxeCMB5rxA7eZwXVNehc4+ix8i2YMkTrk2vviZwZjGsx/pX6X?= =?utf-8?q?eUPW+/d19ORvOexkykrDazZBXrW/UFVNTPvy/XmniZ+BzMmeLS1nEO6UFAag7kZvy?= =?utf-8?q?naQMTyE3oKXI7JWc5b7MNhEUdTbK964wiWivbdGOFlP6gTVuf8xVn6/GCMqiNjUrD?= =?utf-8?q?0x8ClYYZe5ykcj/MXrqEX4E6WugaJfsS8oS8bmMTYQUrRMDGm8thZl3Y=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d8f2714-f677-4fbe-21ff-08dd13da4c64 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2024 20:37:26.2892 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: f33mPSi5zC6V1uCJqBUqHf5IvGN35Qf3K/5vpz5mjETmVJfgyHd8x7JCZlE2TQ5wACic9oQ4f4sPG+8Y1G4jyA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB7108 Add three registers: doorbell_bar, doorbell_addr, and doorbell_data. Use pci_epf_alloc_doorbell() to allocate a doorbell address space. Enable the Root Complex (RC) side driver to trigger pci-epc-test's doorbell callback handler by writing doorbell_data to the mapped doorbell_bar's address space. Set STATUS_DOORBELL_SUCCESS in the doorbell callback to indicate completion. Avoid breaking compatibility between host and endpoint, add new command COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. Host side need send COMMAND_ENABLE_DOORBELL to map one bar's inbound address to MSI space. the command COMMAND_DISABLE_DOORBELL to recovery original inbound address mapping. Host side new driver Host side old driver EP: new driver S F EP: old driver F F S: If EP side support MSI, 'pcitest -B' return success. If EP side doesn't support MSI, the same to 'F'. F: 'pcitest -B' return failure, other case as usual. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- Change from v8 to v9 - move pci_epf_alloc_doorbell() into pci_epf_{enable/disable}_doorbell(). - remove doorbell_done in commit message. - rename pci_epf_{enable/disable}_doorbell() to pci_epf_test_{enable/disable}_doorbell() to align corrent code style. Change from v7 to v8 - rename to pci_epf_align_inbound_addr_lo_hi() Change from v6 to v7 - use help function pci_epf_align_addr_lo_hi() Change from v5 to v6 - rename doorbell_addr to doorbell_offset Chagne from v4 to v5 - Add doorbell free at unbind function. - Move msi irq handler to here to more complex user case, such as differece doorbell can use difference handler function. - Add Niklas's code to handle fixed bar's case. If need add your signed-off tag or co-developer tag, please let me know. change from v3 to v4 - remove revid requirement - Add command COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. - call pci_epc_set_bar() to map inbound address to MSI space only at COMMAND_ENABLE_DOORBELL. --- drivers/pci/endpoint/functions/pci-epf-test.c | 132 ++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index ef6677f34116e..a0a0e86a081cb 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -11,12 +11,14 @@ #include #include #include +#include #include #include #include #include #include +#include #include #define IRQ_TYPE_INTX 0 @@ -29,6 +31,8 @@ #define COMMAND_READ BIT(3) #define COMMAND_WRITE BIT(4) #define COMMAND_COPY BIT(5) +#define COMMAND_ENABLE_DOORBELL BIT(6) +#define COMMAND_DISABLE_DOORBELL BIT(7) #define STATUS_READ_SUCCESS BIT(0) #define STATUS_READ_FAIL BIT(1) @@ -39,6 +43,11 @@ #define STATUS_IRQ_RAISED BIT(6) #define STATUS_SRC_ADDR_INVALID BIT(7) #define STATUS_DST_ADDR_INVALID BIT(8) +#define STATUS_DOORBELL_SUCCESS BIT(9) +#define STATUS_DOORBELL_ENABLE_SUCCESS BIT(10) +#define STATUS_DOORBELL_ENABLE_FAIL BIT(11) +#define STATUS_DOORBELL_DISABLE_SUCCESS BIT(12) +#define STATUS_DOORBELL_DISABLE_FAIL BIT(13) #define FLAG_USE_DMA BIT(0) @@ -74,6 +83,9 @@ struct pci_epf_test_reg { u32 irq_type; u32 irq_number; u32 flags; + u32 doorbell_bar; + u32 doorbell_offset; + u32 doorbell_data; } __packed; static struct pci_epf_header test_header = { @@ -642,6 +654,117 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, } } +static irqreturn_t pci_epf_test_doorbell_handler(int irq, void *data) +{ + struct pci_epf_test *epf_test = data; + enum pci_barno test_reg_bar = epf_test->test_reg_bar; + struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + + reg->status |= STATUS_DOORBELL_SUCCESS; + pci_epf_test_raise_irq(epf_test, reg); + + return IRQ_HANDLED; +} + +static void pci_epf_test_doorbell_cleanup(struct pci_epf_test *epf_test) +{ + struct pci_epf_test_reg *reg = epf_test->reg[epf_test->test_reg_bar]; + struct pci_epf *epf = epf_test->epf; + + if (reg->doorbell_bar > 0) { + free_irq(epf->db_msg[0].virq, epf_test); + reg->doorbell_bar = NO_BAR; + } + + if (epf->db_msg) + pci_epf_free_doorbell(epf); +} + +static void pci_epf_test_enable_doorbell(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) +{ + struct pci_epf *epf = epf_test->epf; + struct pci_epf_bar db_bar = {}; + struct pci_epc *epc = epf->epc; + struct msi_msg *msg; + enum pci_barno bar; + size_t offset; + int ret; + + ret = pci_epf_alloc_doorbell(epf, 1); + if (ret) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + msg = &epf->db_msg[0].msg; + bar = pci_epc_get_next_free_bar(epf_test->epc_features, epf_test->test_reg_bar + 1); + if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + ret = request_irq(epf->db_msg[0].virq, pci_epf_test_doorbell_handler, 0, + "pci-test-doorbell", epf_test); + if (ret) { + dev_err(&epf->dev, + "Failed to request irq %d, doorbell feature is not supported\n", + epf->db_msg[0].virq); + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + pci_epf_test_doorbell_cleanup(epf_test); + return; + } + + reg->doorbell_data = msg->data; + reg->doorbell_bar = bar; + + msg = &epf->db_msg[0].msg; + ret = pci_epf_align_inbound_addr(epf, bar, ((u64)msg->address_hi << 32) | msg->address_lo, + &db_bar.phys_addr, &offset); + + if (ret) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + pci_epf_test_doorbell_cleanup(epf_test); + return; + } + + reg->doorbell_offset = offset; + + db_bar.barno = bar; + db_bar.size = epf->bar[bar].size; + db_bar.flags = epf->bar[bar].flags; + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &db_bar); + if (ret) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + pci_epf_test_doorbell_cleanup(epf_test); + } else { + reg->status |= STATUS_DOORBELL_ENABLE_SUCCESS; + } +} + +static void pci_epf_test_disable_doorbell(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) +{ + enum pci_barno bar = reg->doorbell_bar; + struct pci_epf *epf = epf_test->epf; + struct pci_epc *epc = epf->epc; + int ret; + + if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) { + reg->status |= STATUS_DOORBELL_DISABLE_FAIL; + return; + } + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &epf->bar[bar]); + if (ret) + reg->status |= STATUS_DOORBELL_DISABLE_FAIL; + else + reg->status |= STATUS_DOORBELL_DISABLE_SUCCESS; + + pci_epf_test_doorbell_cleanup(epf_test); +} + static void pci_epf_test_cmd_handler(struct work_struct *work) { u32 command; @@ -688,6 +811,14 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) pci_epf_test_copy(epf_test, reg); pci_epf_test_raise_irq(epf_test, reg); break; + case COMMAND_ENABLE_DOORBELL: + pci_epf_test_enable_doorbell(epf_test, reg); + pci_epf_test_raise_irq(epf_test, reg); + break; + case COMMAND_DISABLE_DOORBELL: + pci_epf_test_disable_doorbell(epf_test, reg); + pci_epf_test_raise_irq(epf_test, reg); + break; default: dev_err(dev, "Invalid command 0x%x\n", command); break; @@ -934,6 +1065,7 @@ static void pci_epf_test_unbind(struct pci_epf *epf) pci_epf_test_clean_dma_chan(epf_test); pci_epf_test_clear_bar(epf); } + pci_epf_test_doorbell_cleanup(epf_test); pci_epf_test_free_space(epf); }