From patchwork Sat Nov 16 14:40:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13877608 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013018.outbound.protection.outlook.com [52.101.67.18]) (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 942FC15445D for ; Sat, 16 Nov 2024 14:41:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.18 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768079; cv=fail; b=hm4zE8RbPpOnQUFoho6tJPuPy1huFhc/nxS38INEEr3wYPGuseBStjtxELJUjtxtDAl6i1E/fQ32nQPYrG3fYlCjoFB0rKYO1FIMMU9hmEPeKCQRTo1FN8xkZgkHbV/GM8Oblnlz/6Tv1PRV3r6ScF+8R5wsggiUJ8R/jFpY+cY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768079; c=relaxed/simple; bh=4vKx2rPx2m7XWgRxYUh6kb9XgUf/PMkH85+H1/AB+sM=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=n424jQT1uZuY48TZcFjF3GrIebgS4Mo/3EgiApxV+vU4xvdgAzONDWDL0pU/SsS8t/64NMzkQGVRaUtwd2IFjDoeaGw37midYt4PAYdGodI8Np3dnZLkM4tn354NC61W6w7RShJmUQv55aI56ZLy6ZnMqcXSdeeUMJLRj7EMHok= 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=a34Q5pii; arc=fail smtp.client-ip=52.101.67.18 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="a34Q5pii" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AMoY2i0eUKmk54rBAvn91rFyjdWFgnLwbKUXaPfsbtxLVBjPb/AN4i/O/MsT3Hf+hVxw/GXGW/LWNjd+Hf/U89tX+luS9yPNjsNBb9hAHzg+trAFco7r1HpUuK8Pm96C2Fdpz2R0cgdYi4VGRkKk4uV3P08KLMTbm2BPKqSTCadOY2VgNBbKKjVqetbs/xMKpja7D7HV84Z6Nj214SAU8FXXwqm0AF9qWoz5+nAwP1nyac8/pQ/6hbZu7o/3SY8G8xdS8q8gSp22Agy+ZHjoJGc6pq0aViPCmUbioMCGasGZsIssZI+3RJJ6dZaTlr8mneSvViOT8EyE3bgMkFAbxQ== 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=AJ22JWiQxp/Dsr6tuhGS3SeKCcsaE199Pas5L1A5Z/k=; b=gupbtZb4kROgRKjpwTf9q79RnzDbmLSHY9qKpZ1xbIsiC15xBDMoWzvyd1tydJ/A048g1Psp6/TJ7D0gb3xxfLA88BKxLkgUoPQY6VB3Rvq1Jz8evwh6MAG8F1EjVpJyWHsSQ11X46NUrlligCn96VOfcWGdRqqXLderKC4NYXCcqgUagBDBGyz0iBAiPM3YOCrMqWifeYiQAQnL/6kq7pZOuEJ5olqInRjWVrOWcgB1byzGpcHtSxT+vunRMuZ2tEwD+Z+UKb1omx6GsXweNvBKYoqfRC+SMupLwaRamzB79h/fZqiu1OrJKMHuxj+twDC66AACLQW6xumC1pE+uw== 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=AJ22JWiQxp/Dsr6tuhGS3SeKCcsaE199Pas5L1A5Z/k=; b=a34Q5piiA4DrLGgONnQjt7iRkD1fj6vJIDRZqGUODznLa70MPv4MceZpg6/Fwjd7WUpdoi1x1BEHeUF0ZrsQ17/uaesJenu78TiM10iwZw4GzsPr3cRbyI1nT0WT0jhmbvzQzQj6VQ7I4IMw6Biez8RPYgp51Puvbju+f+rSseaqB4yYOHcrMzDHATtMxNPpGa3RQltciSA5OylF2/RW8+8072qXZjBy/lKZb7DcyUabkDHFGiKllfQBwLOC+CPuuRqpjL/HxvJQyWDyqDe6jPUs1kvk5yJ1eM/HlriBo0NEXE+6kKXgOENLGBbd8nVwrtB3Dfmb12ho7ubL/HXd4w== 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 AM8PR04MB7265.eurprd04.prod.outlook.com (2603:10a6:20b:1d8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.21; Sat, 16 Nov 2024 14:41:16 +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.8158.017; Sat, 16 Nov 2024 14:41:16 +0000 From: Frank Li Date: Sat, 16 Nov 2024 09:40:44 -0500 Subject: [PATCH v8 4/6] PCI: endpoint: pci-epf-test: Add doorbell test support Message-Id: <20241116-ep-msi-v8-4-6f1f68ffd1bb@nxp.com> References: <20241116-ep-msi-v8-0-6f1f68ffd1bb@nxp.com> In-Reply-To: <20241116-ep-msi-v8-0-6f1f68ffd1bb@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=1731768057; l=7742; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=4vKx2rPx2m7XWgRxYUh6kb9XgUf/PMkH85+H1/AB+sM=; b=Jy4o0qZTn0v5n8B1dAPRcLp2iYSVwNri5rxx4sVkbNfB4zlzngT9PCf95RinIkM9JM7xNXYyL aw5yWDOuiMxD33SVtRLQj5WhtiCnPevt0aVOW3/zTEOAN211kdT581I X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0210.namprd13.prod.outlook.com (2603:10b6:a03:2c3::35) 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_|AM8PR04MB7265:EE_ X-MS-Office365-Filtering-Correlation-Id: e820607b-6aaf-4abc-14e2-08dd064cb9f7 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?bDJrUlW9vgSGQOuLX3JmXZJUASxWzGw?= =?utf-8?q?NqV7rrNVKd3hYXCAHyMEdH+O8gWbS5tWh5PQS6DsWKNx0/nGN/D+9rtjzoSMaoQcu?= =?utf-8?q?2TP8twPTrpl3W+7E6Ql1ApBHsj+jADJSrosVK4jRW8+xAwveHoJMdKglH1rdKBsne?= =?utf-8?q?Z6d6ps8tWmcjSEv/TUkIQ32xPDgR8RONpFO/zima0N6oEHuZ97vq0Ad4RM2Q+Jvrg?= =?utf-8?q?y8dQ9oSPkQCg88pJhClk8BQotI0PO38KzFxK207OMiC+IS4DIEr6Yf8rh0XBKY44/?= =?utf-8?q?wvX6N93SoRTY/VZ++h5xLm78JIEjaa4bVvSHRgiVV7JDRT8yKefwORWmhDPlPVvE1?= =?utf-8?q?yCHzakfPhswdvXL2xo9pmVBm1+d1mIVVUt2puwn9djOSnYtwy5NYn2zGzvsr37W4w?= =?utf-8?q?mnHaFOMwfbPcvJBFdhVHFIoGWmlwoIi/pJJKESuv1PMRvNCiDi3MP4RZvwSbY6TSc?= =?utf-8?q?dYT/JosPgdMEG4laXhrW55gMe2bdwCnsshXIg/5c5RqyUmQTZ73GZKZ8ebxIIsm6J?= =?utf-8?q?V+04sHFI/i3Hd1ZOmHQrniVpwOD7BaNPNDX596f1PSmWkZz9rmdTew0p30h9LGN5a?= =?utf-8?q?T4IJZRpw+DvaqSTHies7zWiZqB1bZji/m69q/R7Ucp2C+m/2CVswjqzelCI3TQk5c?= =?utf-8?q?EekDHsG5gSDq7kcwZkLNWQiDommFP8GzvLlf+NCkMVq7+dzk3UuankXM+mW6/hcfS?= =?utf-8?q?ocSZ/oLAViekX+baPpIOEvqipNDlqoExJSzAqRviDRo0ckDT8wVRuFoi53rEblzEK?= =?utf-8?q?6UmQvItyEjFru6U1zrQRmIF80Z0hNmbyEncxVPcvKe0r4ipdXStzpOoGsR16cVQy3?= =?utf-8?q?uJORL9Yh+Nx0IJkJXfO6UKPhbteO9MmTLWu4ln6oS+MNkmZ5L5I50BD7CkW30lhFS?= =?utf-8?q?IFKPD3bAvJIWXGSIal+fKYpNZdR1mSDp1m0ChSPZuBTutn9vUXcJN8RgGLNO+E+ng?= =?utf-8?q?1ACM8hYXTzjl/ybby7xtmaN+wKTt/y9x77JykQluaFhPLi2Drt+VedkDaQu60fOlI?= =?utf-8?q?EbV/Fibz5s8G1LE+X+5Ih0G8MFYH4nK3zATnO3PnqcsC73611rcptJM/Zg+RjLDGU?= =?utf-8?q?Gay2ILLlIqXDFaf1Cyxh+npvoSdXxnshhlCQA9D2fK/ubbI/MIenrPOF1N4G5D+Np?= =?utf-8?q?EP4dh5kIgVYcmG894WOGceb0bfYuFH8E157n1w0azJnqGUflbjX8XMrTRl2o8kui3?= =?utf-8?q?V40d3jolu8SGqhj/hQDi3cm+6sHJxp3JXq2liOepZ+DhT0tTlDe5qwW9K+i9pOGX8?= =?utf-8?q?oeR2WPqoJePZpgdk0DuFhGt75Z5PaAu8kmAURMN/Ibqwk36oj4Twpgd8=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?8D8WfqaOYRntjRrQMex3C0qKPiFP?= =?utf-8?q?mH0+ckepTDM2iqkKQUFLNHKYQs9NzKJyQY+L6dJuq9m6jqtRUqxMTYMDUEk6W96ME?= =?utf-8?q?vwElgBZqilFNyVTiiMcfFSuz8PqVpbE+lk6gkCKBfLskpawZR9tNyFlMuyIgyIFdT?= =?utf-8?q?kjONTTQsZC3sSTqX1UiUHAv32gdiyWzJj+HG3TXw3mML6hoVxqsHAwAWbsOzFX5F7?= =?utf-8?q?uJ3fGV0HkadX+NO7avlMmWQ6ZQc79Ms1wO4T9W1HDkXXNrePC/oma6NckRj+sX94B?= =?utf-8?q?b4Op2j+t1Ic36LkVMRJv1lugzXL2LLTgrADinnz/MXGXm3KxeEBCGrtGJXKmSzT/8?= =?utf-8?q?FQxR2gY1wARjFkf4pyCoXOiS33+X3KBZxiXUf1NIOyxmlJbCYcmAL/KfwfHDezEan?= =?utf-8?q?6vtPffAw0hYTTPBb7We0aAWhb4soXLXsMtSx6oZEoOIOrutITW0+15By66fQrO1sR?= =?utf-8?q?Etc5bcCs4B0UHVxGb6qMlPtMe2zQWmlQCHg9XiLp94Bbt3uf+EKxmU+aBKvLcZgJA?= =?utf-8?q?z0hbR9g2dAPjrJKEyHsjjIkDZh8RG4GwgLyKCcgF6HQgwjtObrGtnEiT/q5p2qMnZ?= =?utf-8?q?ZtNN9frEUzGf/gFpfaT78ZKObUf8D4lNOCzJvlNatWbuzc2ODtK+dBDbC15pfyy8P?= =?utf-8?q?z///vLESS/qw7zt5Giqgc0/PfRQF5RPBF7dNTHx0Hby7p6ZvmICoJkFR87ZHmGc54?= =?utf-8?q?Q8ST01n2FJP4WQ+Dk9uC4f6jy/nMCQHqD6SbWusdZPHOA7cFWmWDg8WsRoxkBq438?= =?utf-8?q?X0XJgo6+dhJM6wnaDZ97xCL3Q9M+/FCQ5BVLcSddteANjJqIFLS5ZSTymqDkrzhL/?= =?utf-8?q?54rdPLBM9LRtG3MVA4bwjzUOvikbO2Va8ISJm865Bt8U6qGozl6OvhW+sAPx+BUpU?= =?utf-8?q?QbZawMkUIp+4F3qesoIZOQH19tG+0kojUllMpX0KbkB0ElPzA0dm8+PcvneXImi/P?= =?utf-8?q?9JZ3fQicFv6bfqWlWKvbQXAY0YcXWn3Xvsl1RY3KRp5Mjg6H4t7TkV68eM0ruj1Lx?= =?utf-8?q?mrWlT1dO7Iof9W3CNtGCgDkHezzinXgwVS71C5AS5n5n6z9MvTP5dS6n5n+9tiMTi?= =?utf-8?q?Gi4viBvlS/OSS0wLJ+rFihFxwHih3na+fZn6LgGgR9vSmCsT71N1CR02lg8hNSkc8?= =?utf-8?q?lm9lUWhZtFtZcjyDqNRI3ZdLVz+NmmzOufAxMk0L3KRLmcoO0/GtP9rGaYfOkAbni?= =?utf-8?q?GhwdN7buqAX0xychhTyvXypY448GaK0uTIRXtY1EhbqFE5rc0AY5Fp0q6BxBccdWc?= =?utf-8?q?/ov/l44AvfpmB90jzgpwl/xf46fq9Qr54gfce8Ijvv5VutnL0gHONhRPym65SMv2R?= =?utf-8?q?lFWTBxHupU84uRAPR+kYODW/CymV0CDYifBS4df5w41wFtCVxHarJk47Q/jUQIknZ?= =?utf-8?q?rq+HaycHXslCuY8HGuoX9SdJ0yxjLMlR3QGhYP+emjsB6SEbu70h1CU4VZY68ukvx?= =?utf-8?q?HOQnaXGgGwynJzvow2shRy5wY5xaiHqnMor/Y4sayi2OIMgxnhpUL0WQ=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e820607b-6aaf-4abc-14e2-08dd064cb9f7 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2024 14:41:16.4653 (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: ybkk0/tJOnwHSzvDL/ZxIUQtgr0dWwXoBt7/0GVZ8QE5iRV0gdN6z7Xnyn8yVpI/sA9KPfru8xJaRGF45OKSvg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7265 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 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 | 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..410b2f4bb7ce7 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_inbound_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); }