From patchwork Thu Oct 31 16:27:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13858179 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2045.outbound.protection.outlook.com [40.107.21.45]) (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 08ED91BC9FC; Thu, 31 Oct 2024 16:27:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730392055; cv=fail; b=IDBUdbkPaOOqOyD1jLTfcer5CIWH/GNy5fI172bdohGZwF15xO/QsNzUVckt0l0itOauFBPVI9GIm6JyrU1qFr0NU+nUG9KpYD6mNilQelx93peBpIqoc7gp/YEpujDa6ZCnB3RnPH08yMpE5hmvcW4v4kfMURu0pBjaECd2ZCo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730392055; c=relaxed/simple; bh=JYWf7Ivf0hxPXaDhUGKHvnfXMpLlf1E7XiPYVstdBQk=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=PMS5uysOhHUHj4YTv9647sMvwr6hCRYgP5uOD548C4WHzlJlDUE6Nrm33/4e5//q+leYXW2A0/B8v5yigBbR0pTdpdkhIhCHoUxw8blJroVYF42EiZJ7hURFH5w1EGzv9ygAGnNL5U6gnX4pLKuw2+K/f3J/2Zk5mJ8GpaB096w= 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=eMGmy3BH; arc=fail smtp.client-ip=40.107.21.45 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="eMGmy3BH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Rst8UucvP2zB3S+01x9o/LesiTsMhT6gOiA75G/kBIkDqidqFKJfm0Ru8ZlxXsApWADvE5KugjJnswC8z7TCdSqqkBvm9MoHHx5Q16UIPNhcyPmrOlclr/YpMmheolXlKAF7HmJA/0ahIjUUKJ5BTcClckabo8n+9MJDH46wpNBRRiofI8N3zuKKPoAxQb6fQVn3aRdppymKGup6Sy4jqOned7G8MFeO9oEmKDHB+ZaeW0lLb4SAB9YB8fbfMSnMJ8yaQJdAAGfEBAanWzPTuN5C+7khKoLKjCjHj1Qfe/iDGn+W/hfGUwsdVVZba/Wu26Qgn/SZaKEihiMbl6C/wg== 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=rSHhGQNj+pSFlSAACu8GErRxT1442ZWIsPF1u4YQz+A=; b=aao/Y9NalEB2TlHKMUhd0FFrSJEX2QDAEZT80PSXQfcWXJ9ZyBdEkNsAHLj9rNrU7g+Sd1HEy7lLg50PUv6C/ahtuwxVL+ZsjjwnJTus0tR93QdJ5rfrcOcUfsp7PULdMdM3AkIz5yMQgaAzqHHXt6Ifvp4CBOuUS/NFvZvqDYGG8NEjRuYRH6o0OlrYkcfiiTGKXE9AOJicB77l8DCxtdvSxCLeXCxR9bAXXdBxNyJUmc2uSEtpOE1Vt6MPZNnpylgWs73G5roYNSZ3xgGcq/WAMLLe8sDnUHNzmleScviYbHv/J86KQpDH/AhpvgFTk4o35GJtpnXsBZV0yWw2Jw== 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=rSHhGQNj+pSFlSAACu8GErRxT1442ZWIsPF1u4YQz+A=; b=eMGmy3BH8LF/YEXD0foZZGCT62ZoKBwX/2KGTdEqilBl30s1qQvmjLxSo+nnHmNg0lakVtMRUmVzXrrr0P4jynRmBpnLPdjZ7snNOZEuazj2gRmNlLH080zLz4Z5PARN/mk3XNHitifschAApwN5X4QBRae8EVCI9yAgiMDTuLS7SpVbVxuaad/3tZXge+wbteoyLnAfmo7FYubu2zGDYMFVewFkICdtqmayANGt3QETQJoASR41ZCSHn+C24mioZcIiVgTNTRkp/yISdLu93vMybafORoxlYm+fcUjIZnRt/2p5mK7xRIJNoconspObjWuWvlsEmT7xsAqy9gu/Ug== 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 PA1PR04MB11081.eurprd04.prod.outlook.com (2603:10a6:102:485::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Thu, 31 Oct 2024 16:27:23 +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.8093.027; Thu, 31 Oct 2024 16:27:23 +0000 From: Frank Li Date: Thu, 31 Oct 2024 12:27:02 -0400 Subject: [PATCH v4 3/5] PCI: endpoint: pci-epf-test: Add doorbell test support Message-Id: <20241031-ep-msi-v4-3-717da2d99b28@nxp.com> References: <20241031-ep-msi-v4-0-717da2d99b28@nxp.com> In-Reply-To: <20241031-ep-msi-v4-0-717da2d99b28@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=1730392028; l=6630; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=JYWf7Ivf0hxPXaDhUGKHvnfXMpLlf1E7XiPYVstdBQk=; b=OeCLCcpHihO4JQsIb48Ao7gjrAZLLw/jpot03X9xaFEBbgSjRF6gQfbIE8OMXTIo99EeQR2S3 m548nd/NW42AxAH2xW8nHiU1wImcEA8E+jKaxz8S+4gLd4d+xxwf2it X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR08CA0056.namprd08.prod.outlook.com (2603:10b6:a03:117::33) 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_|PA1PR04MB11081:EE_ X-MS-Office365-Filtering-Correlation-Id: 519c698d-5aa3-4e35-579c-08dcf9c8e695 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|52116014|7416014|38350700014; X-Microsoft-Antisp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/lAYUMQ6rjRYTtKNIBizk2QW9pbyujIauLeM5w8Q2tt3?= =?utf-8?q?RJlFoLW5e9jPJCkWfHlNliWCIor0Zr/GF3m8vzCHCfnUPQRm2clqPahZ7a52Vmqck?= =?utf-8?q?xQHshkFOIEB3Q5DroJQrlaL6pXDdiJ0y/JkBVfcfPMOpZjua3mRw3nxGnagCD+3mW?= =?utf-8?q?btDaNEN2bd44jXgsxsG61sAH6jwZjJueLcnKg8pgmcwqnInvBccprtky89N6ykp6V?= =?utf-8?q?ySUUX3jb5nHnx4EiF2JFwQL75Z9JGOX+HoCasngxWSlP3xIhg6VB0U2W+C/gDbOLd?= =?utf-8?q?H1s7DMoDTZxRjOk8K/IqPHMJfMpXoRbTUtnxZ9mYahHMivW4Ld5blUpKcZBM+dHW/?= =?utf-8?q?U09qGbHWIRGbCax/UNvNvurmG26jmRElS0Njn80IZg3DWn/2bt2qqLDz4FUEFu1Tl?= =?utf-8?q?5yY2sOXEm9FJQvb5m0ylGHCHcqgeC0hWC03VeudusS00qkJGNEQ4btNA=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)(376014)(52116014)(7416014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?81Yf7TpqdPQUHmxguxFP/QmeohfC?= =?utf-8?q?njkO5VMDkml4IZtlJZaBMGkLO3i+NJawFngkatrhFelBMw1r0fnj/hwkPedggodwk?= =?utf-8?q?YzSkl9dxJxw6LRHk8fvQZiOQo1ZUZ8xU6SmO6ewUthO/QXYwuVTSGTcQ+PLMqdYkZ?= =?utf-8?q?OVgXP1wafe0JULth9cpHgRDou0IyIOydi1BA1ARJc+iuz69sLKOw2uxSF8YaVybHs?= =?utf-8?q?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utf-8?q?yxqOjDqO+vDxzoC4H2Nl+dTD9NKq//mqWbjCfg39B+IKRosJxQ5IGyDZUhMN7nF5Q?= =?utf-8?q?Togu5jxENOwTBc1cw7Mmp+4GZTQTKZrQ3EkWJFbz7OUJJvaX/jo/ALrT1S1YaXfl3?= =?utf-8?q?lw0ACOMVbZjwVkPwsFfQ1+/pMU+KaQKtq2MNe5Zw9BMGkg7rlXjm8jmfxsgSSOFke?= =?utf-8?q?fPh1a+zYWWj4OvoeRpZazlIDoFBw/ryQxgX1Gvxun6Jt/sfpkSyEjqrafUtFIl3EQ?= =?utf-8?q?+k0QrVtixAsSDqqiSzzbmZUBk26RFK/3ZTkxJeXx0IKHDWRL9J+4hqRN86ZYABQYj?= =?utf-8?q?ZuPQcQav4UUyIGL8nrqhIoi/g70UU5bZ5t97Wna5868jVeSe5m3NbbeGu9mhyR9Z1?= =?utf-8?q?2sHznQsr8N71Kr+nxlWEjoPpv2VUTenKCP1Ut1GJ3Gg0b0AWad0Wji0k=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 519c698d-5aa3-4e35-579c-08dcf9c8e695 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2024 16:27:23.7961 (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: pT1r3NF/laGZcn/LH6azim2vKAanO8vDhBu6aua1+1Y2g4JRsHNhc015jqKjJU5yjFuAELzRDKKERlnVcRJMwQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR04MB11081 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. Signed-off-by: Frank Li --- 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 | 104 ++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 7c2ed6eae53ad..dcb69921497fd 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_addr; + u32 doorbell_data; } __packed; static struct pci_epf_header test_header = { @@ -630,6 +642,60 @@ 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; + u64 doorbell_addr; + u32 align; + int ret; + + align = epf_test->epc_features->align; + align = align ? align : 128; + + 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; + doorbell_addr = msg->address_hi; + doorbell_addr <<= 32; + doorbell_addr |= msg->address_lo; + + db_bar.phys_addr = round_down(doorbell_addr, align); + 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; +} + +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; @@ -676,6 +742,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; @@ -810,11 +884,24 @@ static int pci_epf_test_link_down(struct pci_epf *epf) return 0; } +static int pci_epf_test_doorbell(struct pci_epf *epf, int index) +{ + struct pci_epf_test *epf_test = epf_get_drvdata(epf); + 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 0; +} + 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, .link_up = pci_epf_test_link_up, .link_down = pci_epf_test_link_down, + .doorbell = pci_epf_test_doorbell, }; static int pci_epf_test_alloc_space(struct pci_epf *epf) @@ -909,6 +996,23 @@ 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; + u32 align = epc_features->align; + u64 doorbell_addr; + + align = align ? align : 128; + doorbell_addr = msg->address_hi; + doorbell_addr <<= 32; + doorbell_addr |= msg->address_lo; + + reg->doorbell_addr = doorbell_addr & (align - 1); + reg->doorbell_data = msg->data; + reg->doorbell_bar = pci_epc_get_next_free_bar(epc_features, test_reg_bar + 1); + } + return 0; }