From patchwork Thu Nov 14 22:52:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13875715 Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazon11010028.outbound.protection.outlook.com [52.101.69.28]) (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 931B81B2180 for ; Thu, 14 Nov 2024 22:53:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.69.28 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731624793; cv=fail; b=Hwm7oCCCdV8WsOVgk7TMg2VEbmYNeBPUlpCBdyp1PGrkhNkSixdzpWWN5o716LOy28feG+Vt9EHp7hLbdZdz0T7byxNwOWYwCBj0n42yATnZKk6uD+lzZVpD1T81BjG/JW/NNkaJ+3bwNUnwP7Wo3K2pD78zdlT9e/CMzRCk8TI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731624793; c=relaxed/simple; bh=0yAMagX3u9+aZDCSSioQiAmKlqCp0jSmM1pLy+8moi0=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=SCG6g1HtmNJnB5CnMT/zTBvW5w9LlZQjkYwtalRPQFocIO3X06d970gThwIvIBpynSSzlRh7i9rL7U/O7sIY8laC0bX6akKAaVY5wyI8/DsABhSFFMuxNKbsMQDw7XQZLOawsEeAJGR1A7whXGVOIxBqt/7BVp0qc25V/i1Wbzc= 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=S4Lql5T2; arc=fail smtp.client-ip=52.101.69.28 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="S4Lql5T2" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xjCvIIpSp69BKK0TMNpp/TEsfMteG+XE4TSr9zCZSuI34oT6HtsE9pKcwor3QVtJeCWFOf/EIZXaTI7xftuYRuHJgf3PwUUYqD9lVk0ZwlJ1TkjMApFNl5MZ2T/hwqaqt5XISAzuT8K1enopNz2ZrHhyWHKgSnDNvLSAIGeZPp1OmH6QM/CWJ22vV+MYjXo0d0KDKnqNPKsKQCsCLcL0L6pdhizTOXKEosFLoFwdez2kczAs8dhEGwXehk23Ye2ej9MYtJvWJzGyJw8iUp9B0KgN19myk32nacCtr9BhYfqFBZsDof3mIGW6tUV1OLJHbSLPmUGtya7cA/JPeQO4xQ== 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=S0KC6fMx3yDLGEroWZHuxH6YFJ99NVir6SglA7R8IoU=; b=pniwC+AAvj2EFKtoEHlStDoKk4N0BdzY/51KwROynhNl0JorIghpgUbYfMOh4iSvcbtRDPh+HMQ3mc5viQ3XiwuBw9Vh+pVlVtFkynMPdPrP2XfWBTX6dafaeqXt8LqU3tH5FUzxG2wUDCQd62VhAB1ng2UnGV29CB4jTMxFTuxZrShiTdQKVKUNFhEz/AluWZLurbZEpi17C4F3Ockp4GgdynEwB+bVfffCBgch5iuFQWCTXTw8ZO5ZtHEt2F+UgruVVSaW/ny0+ZCkxey9eXnyTjtoVimk3GeO8zTm+EyEKz6lMC/SnC36uQndeeoaBQhTG9La0tQvjd08FuJS/g== 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=S0KC6fMx3yDLGEroWZHuxH6YFJ99NVir6SglA7R8IoU=; b=S4Lql5T2KaTLOBOuZKrppzQPJnNPqGDLi0c/fUti/oSxh+1yXTZXHwQlwNanUko9Uj2cnG40hALipH82vUSBCS2Ty5tKQqWVOjpc+S2DQM5W/aP+9T9P6VKBzd26vC6xaNSyCeWw8CxFo4Iy6UL4guuF47vd0lmZvM73Hu5qkHhiX8O6gLBN1FRZba/FKw1dSMzpT4eEIp2yPfIK+c0G2CiHzOnTscOWO5m42kW88QXRLWyfzmmEYRaN03+8RIBED7+fmYXKk9h91841b7Ve/TjUQDpmPjpgLsWtehLI/mHx/jNng5xukzZEM6SaYMI/ADwVMBQEib189X1SgqtosQ== 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 DUZPR04MB9967.eurprd04.prod.outlook.com (2603:10a6:10:4dd::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17; Thu, 14 Nov 2024 22:53:07 +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.8137.027; Thu, 14 Nov 2024 22:53:07 +0000 From: Frank Li Date: Thu, 14 Nov 2024 17:52:40 -0500 Subject: [PATCH v7 4/6] PCI: endpoint: pci-epf-test: Add doorbell test support Message-Id: <20241114-ep-msi-v7-4-d4ac7aafbd2c@nxp.com> References: <20241114-ep-msi-v7-0-d4ac7aafbd2c@nxp.com> In-Reply-To: <20241114-ep-msi-v7-0-d4ac7aafbd2c@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=1731624768; l=7661; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=0yAMagX3u9+aZDCSSioQiAmKlqCp0jSmM1pLy+8moi0=; b=9fgUJt1DvuUMv+mualC4PrkA/qGPlkwbMMF6lQzDwfwBiDhnpYfaQGOTdKPycxxlit8ArsMx9 bDQ+Bcr6jjyCP0lRg/fm5OD4mrSuKQE8yOlYzDPs2S4XVNgFoRKGIj5 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR03CA0166.namprd03.prod.outlook.com (2603:10b6:a03:338::21) 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_|DUZPR04MB9967:EE_ X-MS-Office365-Filtering-Correlation-Id: c25f5d4d-47b6-48b6-72cb-08dd04ff1adc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|7416014|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?HSEsZG+mQjznb8QZSGNMxYrynSe6qf0?= =?utf-8?q?vb4QliSIzkYk5pOGy3f1ftvrF0QWCcv1jQog18/KNN2WBAUH2bT+zBeyn9sFjJuZh?= =?utf-8?q?t8mhsgr8JZ31tyKOJlyzHTe9gVe9WUIyIoCSMlk0BS12oc/qHkJq1Zw5bSDfF+psm?= =?utf-8?q?NWJrWNvZNYcE/QzBYPif/2L6VTGxlyv6bir+7l86pnZLjYSVNNxkETtRwb7KpTuPl?= =?utf-8?q?qMS8qgWh+6rlZn9D5JG9rGoDCMk3iGBB6SdFg4TI47atOLqbfgCIcpScdjlPGlBPI?= =?utf-8?q?pkzdiRUfvefW/KgDzfbDSI/oKe0/UOMT40aq4C4udQn1tjQJKs3iT6Oyake6DnU9V?= =?utf-8?q?sfqJiixYrYsWm6kG6CCbRoRmk9wO6b1R2+IewzRcOv4apbCEyNMhp8mPqxrTj95oi?= =?utf-8?q?y+v1q42D5qeAahv1dozhZkgOnf4NSngrNjuy86lCgKaSKjLB5bRzOza1qnz/jtBFR?= =?utf-8?q?CAhy0hpkYAbw5iT1ed0cIlhjjw+tSwDbHhqc8Y4E5ICnJB/1Ab9NTZB34kxa7zKPd?= =?utf-8?q?eATulx57eizEQfwDvc/SbE6eeObU9xP6f6hUV+moqwKqewg//ACZOtyebcxf8Szju?= =?utf-8?q?owTYAHN3v2xN8O2nNGlJIEhkEc2g35m1NHYetsQM7dH6JmoHz/25IzFr/3YEHDnkX?= =?utf-8?q?7qnygyJ8MA4LafutWy0gLNB22GYvQF3O+UcGhnwKuEM8NzqtGVdtJjOj1ff5KYQE3?= =?utf-8?q?RlEBOUFdFU6ZwDfVJlyyBzxfw1ekbjlt3gwgdG9aHV7pXBFTqnaXnhewly0J4WI3s?= =?utf-8?q?5HIQr7LI8hev+M0DivxmzB4QQLcVimLnN3OT2W602pH7pjNXuFfIuAiUvYfZgy88J?= =?utf-8?q?U3GpvQ8MV2h8DfhgywiMKi79cW/s/wLKSwb/Q9F4atY+VNXlRM6NX745wktwotB0p?= =?utf-8?q?QeIgr/xDJnKq6BqV4M/6Y7h+vEnRwgLKbdaN3Hpu8yQscvWIWWQlU9gmwB9CQEEDZ?= =?utf-8?q?InIyAPKGPOZvN1ZULU0my/XSHr1oIvQ5DIrOvb+7fz/Kv+hl5dK5oodsDiu7luNpT?= =?utf-8?q?xOK+jBZyb583WZZJLn3PBERCr2n64jzVf7Osx2q5P+n81Z6qtgFv0Q6aAMvTYIPut?= =?utf-8?q?zZcMEzAaASHYIgvCim+pLzgHjYUXg8EZFZ+Aq3CFquJQsjDOX2o+ngPvC3SUhxUQt?= =?utf-8?q?mvdLv5i5pEiLEVJwSR2xACaipAEpEFGn+EvAyJrrdH1AhYWf9LyyJ0wb/36MDbti9?= =?utf-8?q?LuNBagGNr4CiiYwYowQnrw4hCKabeSR0bJKYbuYumUIfdrv4468wK4Og5C38VE31W?= =?utf-8?q?B6iEuZzQRVJ2PSdULa1vZtFMiGTFwkOYjjYokdyiKpSMghnCc2gMLCAg=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)(52116014)(7416014)(376014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?HAk4zuW3SteQWkBFf5bWe6T3daSR?= =?utf-8?q?zYEvYDZ5E3Xc49VFHiJ81PM86UoQajcqacIzent0CUHsJhRkfZczqYLPmkmTlkXM4?= =?utf-8?q?z+J3kXXD4vM56IvAHMK2Y0QKkVC/h0zrHlvhqeMGfFHZTqcy9ghqdTWSpQLBRxNoe?= =?utf-8?q?fdZ2ICqrFlquLtP95uN27cdjPITpID7nDY4y85ZCOiVorDb8N4lC6IB5djmj6sXeA?= =?utf-8?q?7CwToZzG0BS/3uR0MdanPXcFYXtqgozy7gAs/ojCqU+AxY95lN/N3eh+eUFtVU3RD?= =?utf-8?q?u6IukhUdNhR0gnM299TqD5ZfY+41WlbKDf2WktgY5bOM0JuXvn6NHPxJ3A2gkaSY6?= =?utf-8?q?Vw4CQlW6lJsqmXpVI8TSq2d/jWHcGZFdYR4b6ltdDxuZ8WiC4WwVNftEJBHZCblnX?= =?utf-8?q?lz/9JevoT1+92EIm7MxA7AOuMH+ILHh6HegYjNpyyA0SQz66Z+vEwHfBLzJ90LN8G?= =?utf-8?q?j6BhBuTRbVP/DMNdOnV+fMiEB7PcOIKWsT+yynZFAV/WhwW4lpsQ/ZJOwG3EuxVkl?= =?utf-8?q?kOS6Z7eIPiOKPKiTY5hGFGg4V5XAa9Z6HW7p/0XKExXzS6zBlzBg+cjSigHdUr2W1?= =?utf-8?q?Kz5fnoCvFP1Ulkfmcb2j4hfqEd8lHJdG/GzBLro3oAjWgYWU2sN9u4emoIqh/4lRs?= =?utf-8?q?JJxwH6DdLDW+qPUxChdOMYR7huKfMUfOUtQhh8N12fbMWl3L0unA506qmq/K7Vo1g?= =?utf-8?q?RiRfy9lglG+brAIAV8HFUuqQn2NmJRBW4cYwa/p0Nnegjq6viFbSmo9QnNeHe5gPk?= =?utf-8?q?tWbXXuH8F1VktbrgQoHBbMvEs/gGnpOcBkXVeAntRUavMuAuROfWIBc8CqQn15Ys9?= =?utf-8?q?xkJXMvrYelVNUiaYJqoD3z4yWc2oiDWADXhNBDYuTy5iYaibw/ZSne3qBB67gRtrB?= =?utf-8?q?F1ewvSKVDZdzDEa5luKwuxZpb21S/6MO9J63ZaGP1ZyQ6Sv9LM/RRUwMG8v4J38CJ?= =?utf-8?q?tRgHgFNe0IKDAGPDvTfx7xxsisNBNhvHheQYldmwfaAcm4giYOPRpZIs7Yc3OfcqP?= =?utf-8?q?5JGSUsD5/uM6ufa2vz2qNtDvLkOamrgmaj4ZQRVHLjXf8SkfWzt1KgTnC7HjFcmGQ?= =?utf-8?q?J80GJFNEciusFZCekBubCg04MMTC77x2sxHOkH1XsnUnKm8Xj4vdKFhMY24HxvR4s?= =?utf-8?q?Zme2L5jQWMvVzmtWH7PJnG/0ojoLLP9coQ8EHaxM7iXVmcLFv9NvbjR0uSvjBzlpV?= =?utf-8?q?dJLrcUooFKLu5HKLb1d1jHDrQocOrmNapJ1zxwqLPuzrnbI5t4fFREL4OQGJRinJm?= =?utf-8?q?ukdx263+91+5gw5tN6Z8yev+VAcD9ZmvXDJn8bXnuXf3Cu9dHJjU9qnjpB86zOou1?= =?utf-8?q?CQcgDqtzwOCK/rb3N897m3jNn2jadAw8NKXkcvGZclrlA7ljEqbVis4dexqpThCwH?= =?utf-8?q?PgjwabnrTZd/mocvuc3c8ppAudvKB0CIumSsnH/UK+4Xd6OFaIOcGRgNVFgSh3p6f?= =?utf-8?q?6oPchqJkyeGN3pmnORhXuNYsbrM25yqUMgXFjCSISRtdtvxQhvZqsRXM=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c25f5d4d-47b6-48b6-72cb-08dd04ff1adc X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 22:53:07.1727 (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: Yba3KdaYOb4T7Ri4RSsXR76RcaRKIjGGKOUJRb6jX2Zgtb5iinmcm76soTv9c+1ovN5cHt3zLdvkGelWn9vS3w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB9967 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, 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 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 | 117 ++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index ef6677f34116e..6077a51bbd7c4 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,63 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, } } +static void pci_epf_enable_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; + struct pci_epf_bar db_bar; + struct msi_msg *msg; + size_t offset; + int ret; + + if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + msg = &epf->db_msg[0].msg; + ret = pci_epf_align_addr_lo_hi(epf, bar, msg->address_lo, msg->address_hi, + &db_bar.phys_addr, &offset); + + if (ret) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + reg->doorbell_offset = offset; + + db_bar.barno = bar; + db_bar.size = epf->bar[bar].size; + db_bar.flags = epf->bar[bar].flags; + db_bar.addr = NULL; + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &db_bar); + if (!ret) + reg->status |= STATUS_DOORBELL_ENABLE_SUCCESS; + else + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; +} + +static void pci_epf_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; +} + static void pci_epf_test_cmd_handler(struct work_struct *work) { u32 command; @@ -688,6 +757,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_enable_doorbell(epf_test, reg); + pci_epf_test_raise_irq(epf_test, reg); + break; + case COMMAND_DISABLE_DOORBELL: + pci_epf_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; @@ -822,6 +899,18 @@ static int pci_epf_test_link_down(struct pci_epf *epf) return 0; } +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 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, @@ -921,12 +1010,34 @@ static int pci_epf_test_bind(struct pci_epf *epf) if (ret) return ret; + ret = pci_epf_alloc_doorbell(epf, 1); + if (!ret) { + struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + struct msi_msg *msg = &epf->db_msg[0].msg; + enum pci_barno bar; + + bar = pci_epc_get_next_free_bar(epc_features, test_reg_bar + 1); + + 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); + return 0; + } + + reg->doorbell_data = msg->data; + reg->doorbell_bar = bar; + } + return 0; } static void pci_epf_test_unbind(struct pci_epf *epf) { struct pci_epf_test *epf_test = epf_get_drvdata(epf); + struct pci_epf_test_reg *reg = epf_test->reg[epf_test->test_reg_bar]; struct pci_epc *epc = epf->epc; cancel_delayed_work_sync(&epf_test->cmd_handler); @@ -934,6 +1045,12 @@ static void pci_epf_test_unbind(struct pci_epf *epf) pci_epf_test_clean_dma_chan(epf_test); pci_epf_test_clear_bar(epf); } + + if (reg->doorbell_bar > 0) { + free_irq(epf->db_msg[0].virq, epf_test); + pci_epf_free_doorbell(epf); + } + pci_epf_test_free_space(epf); }