From patchwork Wed Dec 11 20:57:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13904145 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2048.outbound.protection.outlook.com [40.107.104.48]) (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 6BBD6240363; Wed, 11 Dec 2024 20:58:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.104.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733950701; cv=fail; b=SpWLxAB/FBk1sLqnjnIfKIIA6y7wAk85yF8hNZ0jt52IHAMUhVfaI4cv3zd+51HmP7+vCGS9bApfypEk1OfCt7SpFEsjF8v1JmKoZp3Uro4G3nOYZavGXhdtpqBhHfnxGK9Mxs3WE2shMznLbdVL3CpBRcM5nvkSa/E0UrctTzo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733950701; c=relaxed/simple; bh=NSt1w7/3wmlPaEh5ctXXeRua0ok+RFcPLkw2FWIyCuo=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=Mm7MlhGX/bZ0R4X6WpaMZRVOvymwtbkO7VEVx0WRe7MvYqaYokxnf8hcWfkxjpbsmm1mQA5wFatYH6XucYOGIh+n93q04DeDwkjQD/U15ExhhvFuRrCJHPBgqKIOBci/2aNA9qy/Wrl1fiKiKC9+TDDbX6it/6YSjnlMkdczovg= 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=Ztx7JL0o; arc=fail smtp.client-ip=40.107.104.48 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="Ztx7JL0o" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Hk9JGHQXyUaq5PxBDwg7NvuWtwh+Khw6k3ixAjtQ3nOo70YU149ZPd1XDLxSFk3pOx6LQfeCTrJMJVg2/26bn41km4DDos/1W9FUIWKewkYciUN2enFkHOMz+xVheaD/oPO7jFCReUPBzmja8n+KAJggH06gm9WlTOYXCzVQdQMWcIcNK0pjG0uvWt9A9m9pTM5IPvftSQL/4/2isoB9W7CCKesgsxrMHrlaGqcd1rlXGHVrtuQzGS0DUB41x41wGG8ijB9KUHQZojlE8sWbeaTyARPcOq/LO7owT82i/bnlXq0ZYQWl2mJaLym0ePTRUPRdL9xXhGMSDP64BQZSdw== 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=PvGhWu8Gge+T262HkUIK7US4UiQybpzMJMwLoHNGRwU=; b=XW0mBMqG2INDVwf+wprT1zaRFonCaaGYoMVOQuUZskpl77Q31iGdXpTjSogV43HMoBFbTjI5C3C8pGRYq43xYTGejhOTQtiUpPB6vnADVyTUwx5SUeF7OuLQEP6NbXorWcQ1qtnc0o8SDrWrvSkX/CE8qNHZbGTQiyhg8x8aQB9KCXw/nOII1UGG9X9IRQmnDsvDb7nfodBRKxKOPrpZLvq7wiwIOXiyjgi49w3Oise0OqaYRquz/d66tf6tMjerqRVVe4CQ0/Yz8Hf9kVNsWttsTa13JEBWnaHLV4ctN2zeVWBqZQkYv6ovmXqm+YfAs7IjJN6kXlWWcfH6odVxnA== 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=PvGhWu8Gge+T262HkUIK7US4UiQybpzMJMwLoHNGRwU=; b=Ztx7JL0oRheYfL8mkw4IWxVH8FjXov1hSIh8NAp3I17w6OWJvS4Tz4868HnfogH4NhtK/yxiHlgFacdHudumIqtFJandZRszYFQedPq6kFlKxKzrLrGGpnCSI73SdVhXGdaT0xJbfByXQSkmaMlxcdJOSGmcW7dP83OzC+/gtAVqyMXtrRxd0wIh+dt5fkiwTqwq0XR2fCwQRGy3k7PbdbEO4HRh3U1u4tVhg3ZNvd/BQ/JkRt1Eje1IxE4K9GVWEDpegCD4k2Gz70eVXTalfLTnZoRk//oq4OwkXVY7yyOLimmPdj719gzXOMOVBey6VM3p7iGZIKBBpVOWL3P5mg== 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 AM0PR04MB7139.eurprd04.prod.outlook.com (2603:10a6:208:19d::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.16; Wed, 11 Dec 2024 20:58:18 +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; Wed, 11 Dec 2024 20:58:18 +0000 From: Frank Li Date: Wed, 11 Dec 2024 15:57:35 -0500 Subject: [PATCH v12 7/9] PCI: endpoint: pci-epf-test: Add doorbell test support Message-Id: <20241211-ep-msi-v12-7-33d4532fa520@nxp.com> References: <20241211-ep-msi-v12-0-33d4532fa520@nxp.com> In-Reply-To: <20241211-ep-msi-v12-0-33d4532fa520@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=1733950663; l=7892; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=NSt1w7/3wmlPaEh5ctXXeRua0ok+RFcPLkw2FWIyCuo=; b=naHZNzdpwoG3x0/z5Q6iRQMjrj4BbsUwmHXU2VzDjweC/9l9EY1MwTeZ5H3BdQHT7kFF8DV2g oCqWk3zyeaeB4egXZPNE+AIjc887RVYAt5GW4BjYDGoSLGNuyAaPuCA X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR01CA0037.prod.exchangelabs.com (2603:10b6:a03:94::14) 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_|AM0PR04MB7139:EE_ X-MS-Office365-Filtering-Correlation-Id: 0a8b3db8-4504-4b4d-be26-08dd1a2689c3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|1800799024|7416014|366016|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?CPMZ1fkKx33ntkZW+zIhP7+bfrMsRoz?= =?utf-8?q?L432qwH3PBBa8CqUpYKfZ3qrvFYEwK6k50vswqYKD9iqY1aR8kMgZFksBkUE05zm8?= =?utf-8?q?URxPkdtBlak5II5XRefSStAcxgly6Qo6jaZYqGbXO7VlmW+Q0e/7T0ftma2u+JH7D?= =?utf-8?q?2+RpTmr+5LHVLXlxoU3LSjHT7IlCBFCcy0caLm/Ys0YXKC52WTKBYJDRXKi48zdUZ?= =?utf-8?q?qLlFjwK+sO0Qm4Nr+a9nrJMiYO/BkCiKYqX3OD2NRmNv4JEU5+cm2/YpetfFZw/H5?= =?utf-8?q?D5pGC62+Lgbu8qsBtOvPHtioUXBHts0LlaC5lq3vQOCy51DIM0SvwsZkp3mafWl1l?= =?utf-8?q?me4I7nT5uWm/idjt5k6Vsl09c+w7uQrYxypoDfw8YpKhWN6sbPyG1kqT33VBS6Pri?= =?utf-8?q?GE8cn2cFGW0Nt1JM4Wgj0Bo29ZBGYnUNVIm/yvIdgcKfPesiMC6WCVxE32R1hJmsw?= =?utf-8?q?4iYyb/LusV/e8qsAsXnKrKSE5scSKa58P+/V2JrLy+Uwog8rqQLg7NVr5D872t4ej?= =?utf-8?q?yyrRobfvhTMAfWQTXLtj54tq2MFBhxOxSWNSqojzyb6LkQz4SYr5Q9BEL2zleqEdk?= =?utf-8?q?mn6oSeT4+1IPt28akLU3tepNGg6LA+3DAnF+fSm4UFBXunOSm3sknLPzKEPusp5/I?= =?utf-8?q?l/6wgkNOZPqgrtZEZV/va+Uk/lTJLoPItt+RefO65MpIR4YodmixjM84Cvxpz76ul?= =?utf-8?q?FHYBAajdKCPlCWjJSLB01o998HVM0H2xajAZNx/x7hOcGCjRc+Pf9n4Yyo2gr/nxd?= =?utf-8?q?MifntOIWcjSC1i+KGpYlywKdgQlZsqqY18VK5ofgqt2OaFPFntqYEE2CpigXyX0Eh?= =?utf-8?q?NF5gleTgMFK/QBE2RZgdBkntJ3A0OecvEPBGi/9NR7TOvEJS1NOxRq/jk5v/MMEzd?= =?utf-8?q?nmJA/lNUFO0oVVUayAkyyodI1R1bjvRe20EIxjo+W+hlNGPZavVNq2I5s4ZObij/4?= =?utf-8?q?gW0L3tvH0Z8e8iedMy2dPNV8AicsXqrY4ng8Xxy4kLRFJaLHrtz2Br133WoCF7dMI?= =?utf-8?q?/rGIuLJMcHJhOf6GgN1MnwyUYpwOjtCF2pNMdO7/y5QcZZ7k5bYnE1+Sm4E9LFbM7?= =?utf-8?q?uYdfkFOt6VWGu7A0pGXxAgG5fHAFks+VeQCnBwNDRPaH8w6hW8mnMqX3SCzHktgMw?= =?utf-8?q?DT52XGpP7u23jKe0Y+EyzoKRInhD9omvWz0jQ1Egegvmsws/TrUgt5TOp9ZQCVZH1?= =?utf-8?q?f8GaI5KMowis5kOHDAlY/B899RWQAXhJFTHsgbhWG1Oxxk+kX0zyshbs/EDfjyAUL?= =?utf-8?q?42TGOQ/AvKnZAJxtvmk1ZEIk5IxN6idFj0ifcUxheUG0EJHSVQh0TmPBD4Hc4/VVD?= =?utf-8?q?xqpEw8IIIOSmhm1mUByGXkoFxSiyN8ySWQVkibtmgvZZcvDjW3U8O3c=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)(1800799024)(7416014)(366016)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?oi110hS9gs9FBlE79QueNmBx5N+8?= =?utf-8?q?VmEYKe8JffsDauwPGFOB4TbHNKaofIar4bfbrms5anIpryqPIMwhZGh3C5FSudgQm?= =?utf-8?q?tlqltUozv+jFFAQEQnU2kIkg0BLorqyzsvfAaFae3S4YbVnAmkVGcwuFw8Y3cm4zz?= =?utf-8?q?7IOZKMLCsOBr5JcfnJWPx1dLIAQAWfiqeYqPtZ4Jkexp85AoOZqN0jdYQ0vJGWYTT?= =?utf-8?q?n45VQPPtBZ0AHqNKU2PoigypZ1KMylGBlw/Naip6jc3tG145qxibwV3310QblYLwH?= =?utf-8?q?V82syGPxD9v+CEtl81G7blYj/2bar3HD1sl3QVixuXpQMb2UOQxQMbOtgb23vjO9X?= =?utf-8?q?BiwNaNjPvmXZadXbb/RdKfk14iTN9XgzoLaDGlbsYTSCnqkN3MnW2XhvREbm8QgDR?= =?utf-8?q?Y9FR61jW34e7bwA/jJhO1hmLBv2ENav1JFDOVvrEE2RmaLv5hyTJAr8My16fCrneM?= =?utf-8?q?POycAYwAKAR5o7OxMi6XHg0Ti7FR5v63S6kVIYtx+xkYn/3gDIko8Q8bYAkmLZZE3?= =?utf-8?q?e/lIXpPhnOGSFGLoTh40lIcnowzuzRYkizjxnkycYQT4cJI4O4vmn9w1L+aQg/1L6?= =?utf-8?q?7u3n0ETpnmxbCPAfKTq0r/bHHbIHw787t411LZO8C+BEIygaNStnAHXt8NwHY0IfD?= =?utf-8?q?oGwWkuG9BBpNx7j62uE8ZGKKZwJ84zTecTpmtj7fQBm5AX2qd91+lb8qERB8t5mJa?= =?utf-8?q?HX7ZQ+Bm7wSB1i3Qzu/FbRxkYrgH3FjE5BYdtZE128GzZCRsuf0qNGcDju73iME6m?= =?utf-8?q?kAiW5BT52SUXC397ApZgRolH9fsWENG/ZdOc3jefjYnSePcN+Hn/N864qa1YHLjuU?= =?utf-8?q?6lrTuE3bHn5x6O6kl+SIwdhX77NeYoEz18ddQ+urTerdBb8FgEeAMznIjk0E7vL4Y?= =?utf-8?q?mV68+1b7ZY15hlb4H99tygP4UYxJCi3uJdzqhDm8HhUfQH29IgixjM5Vkda3lKpf+?= =?utf-8?q?gqNUty82+br01fkaOS2/RgUiBd7wj/+HTTNuYGa+/qiNz9PHryrX4Vs2hrLJcZnEe?= =?utf-8?q?WsP0nWdTd4MDSC48ydUjcj22BbysouvLnWjNxcvVgJvGqEnSvhOcjuahfAXoTW1ru?= =?utf-8?q?rlwI9P4F6bGPoV20IOOGFnYzNeKyyegCG+vNgpPB3n/odlzQNM0xPWtbNvg9IbGMr?= =?utf-8?q?6zlS4zkPHc+CkAQcHPV+p0npscQFD54IDLfYHJA/FUTjOV1vdF/NZApfrp1BcL1pa?= =?utf-8?q?pU/jSHYPZwroMEmmwQ6LahtjRC3ibRCS/QJ1hzf3TGWE+YHtc8kdoE7f8fkGT3613?= =?utf-8?q?b46uz106ZOX9VHUo33nu29IfpTqOnygFZO1sLroBSAvSBQv7BTatHOYRWWNAS/jES?= =?utf-8?q?emkQQ3tTkQ/jBG2hoTT9g6vemv4YlrAFuF2cOHiT5GwmVNDpTedUk2mcDXiWQS+Z8?= =?utf-8?q?tVCC9ONZ/pbVWGuLiv9jSeo1DQsw/wfXiVJWfnbCYXqbw1YGWDNruC9t3JgNdwEEf?= =?utf-8?q?iLQtiekkfVlF0XKJdsRcjx5C+8Nzxu8h4a0Qv5XOPhyJ2S4gcCoJJfKDQ5Ni/GkKB?= =?utf-8?q?O1VUryNyKhzB?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0a8b3db8-4504-4b4d-be26-08dd1a2689c3 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2024 20:58:17.9984 (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: 7+vszG+Xg4m2TwbvnOpMwDrpAlHuU97ryr0GGGRzMFN35n9INtRL97BBBxqRF7mYk+12weDMXWQo1lufnrdBMA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB7139 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 v12 - 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); }