From patchwork Mon Aug 15 21:39:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 12944094 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 40EDBC25B08 for ; Mon, 15 Aug 2022 21:43:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UdvQwyeaeWi92Dea9uIy1cBLbnvjSti9btrp/lpvt8o=; b=I7+vEBn4WE6IPO Zf8fGEuw5gBW0qHkCgO8pQTBnMgLRwJhsJGpkfyBEo52fGFoxSL9n8yUUrQFgcDRSNxcd3chbShD9 1ckBVsfttrkUfgfYhOFkHUslUA4yhblNqrUQ22dmbfXqYQtJMBw8h63xVe4Mp8aaJS/VEL7t813wO 1X7af9BEFzjKFcLj3oNMKt/LEfUTt3w1mnMqkkdfHzoIjLV6Wutw2M0NCUpRmde/AmlhwRl5lK3Nq x7ucdwpF4Hi1M7OkqJjx+bjyxvAnDJlbBqOezZ8wjsPFSVPnYxwK7EMkFw0SNpvFPEt/YYKsBCAXv OJkV5hjfAtUdgmyXLUzg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNhqQ-0062dE-4e; Mon, 15 Aug 2022 21:41:59 +0000 Received: from mail-eopbgr10055.outbound.protection.outlook.com ([40.107.1.55] helo=EUR02-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNhor-0060wM-0C for linux-arm-kernel@lists.infradead.org; Mon, 15 Aug 2022 21:40:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U09tWjYbMbWPGFcg5jArO5SZsOgWn5vakCtu8ypzSC080QdWvMwJGVtHynGeKz+WYsAZf29BDHfkC7/yqlEEPoG9pvDtyM3sEa1tn2Z6sc24zWvtfXxE0I8cRGUyK3z6m799YVcDSWVo3HfiWHH5RKTNSXsCegT3C29iHccX8uW5ps4GTlSu0ZQ3L7tRQyAmcdYfF2pDOOKkq1CC0yPYiPBSLyl0PZs+rKZ5wZfUIYRSUu0+t45feMdeoz0DDFT0OfYiWIt95wJgfzeRpQHKPuzNZ6XeAWeOVoqJHe0vDD+5FX+KtgzbQ4sr7ugMTzz6R6aOrNAYnpQUlMWuLHl5nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=g1NdUcLeUXF4fzJDgh+3FCiqhJxBXQ8qbrSj5WgwzKo=; b=dGVSt0ORMMQ8NlpzeOimNs2SxkM+lexFGeXAxFpxhTQQOpP7wXJXEZdb8G5nVSa7a1raK/Vh8rAX/Zp488koC2Z1iHSBhl9Y8ihm32rDh2tcbC4OUl/zZnFsJuDTIFY58GreAG6bCFCo1OfvQIaAcbF7qlwzmXiixRn7yBFUotAKdXR04/q9QzuuTd8sZ4y274/NLXiM/j//HVEs1Hb+RVi/PHzC30ETwK1jxUAaFmCjObnN8DClIGhZHwBS5CkLNfwPgUtKTzJqzZXtKClXTjtUxs34aGPQBfI2yc1K9JPKyrQ6xzA+btm+SIstVwH9nHOp7m+lzmhf3qWu0cdNFw== 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=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=g1NdUcLeUXF4fzJDgh+3FCiqhJxBXQ8qbrSj5WgwzKo=; b=XAJEEZbIfZfKGnXX6DjsKPWHY0IowbDPhiRP1WEF/BAGwKldnSYG4FHlhM9zWUySUWBT/kauJ5E+drFd3EEtf0Ifu8qe+P/yr6fGZ5CweVNHLWnwGmgJ0r3uBgntOp4ugHeFMtpzvW0KS9HHOSpNjT9TJBYyqt9h8hETPmb6EcI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9186.eurprd04.prod.outlook.com (2603:10a6:102:232::18) by AM5PR0401MB2580.eurprd04.prod.outlook.com (2603:10a6:203:38::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.10; Mon, 15 Aug 2022 21:40:16 +0000 Received: from PAXPR04MB9186.eurprd04.prod.outlook.com ([fe80::c5f1:b708:61db:a004]) by PAXPR04MB9186.eurprd04.prod.outlook.com ([fe80::c5f1:b708:61db:a004%5]) with mapi id 15.20.5504.028; Mon, 15 Aug 2022 21:40:16 +0000 From: Frank Li To: maz@kernel.org, tglx@linutronix.de, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kw@linux.com, bhelgaas@google.com Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, peng.fan@nxp.com, aisheng.dong@nxp.com, jdmason@kudzu.us, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, kishon@ti.com, lorenzo.pieralisi@arm.com, ntb@lists.linux.dev, lznuaa@gmail.com Subject: [PATCH v5 4/4] pcie: endpoint: pci-epf-vntb: add endpoint MSI support Date: Mon, 15 Aug 2022 16:39:36 -0500 Message-Id: <20220815213936.2380439-5-Frank.Li@nxp.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220815213936.2380439-1-Frank.Li@nxp.com> References: <20220815213936.2380439-1-Frank.Li@nxp.com> X-ClientProxiedBy: CY5PR15CA0006.namprd15.prod.outlook.com (2603:10b6:930:14::9) To PAXPR04MB9186.eurprd04.prod.outlook.com (2603:10a6:102:232::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8a71fac6-145d-49f3-ae68-08da7f06be15 X-MS-TrafficTypeDiagnostic: AM5PR0401MB2580:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WiXYlFO/TrmjrcBxVAI9xpchPGoyQAV0JN7pE3UPK1X1jJ1+e/+MCL8oP3Y1qR3J8AIq+heUiZte1DtXI5zTL10+kcE7Kvf2Ybc7kGK53NbOamIEymAjh2+p8m3hT9HDstJXo/6q1vIN8x2QTilXWgh1kPFKTGBeFmNSYNyNgTdFRIyDHC3fBQ6fDH7hLv3YrnBg8YS5P6+DCNXZctd2Pv+Y24n7LsqFxxiL8+76iYR4ZI1j2bqzljnir1wT9RjmVggwi0FMsjCt+gmNRLu4d6Yf/RydNGjZf93c42qYW1iGQXmTvZnbYFEwj/dhRJj8carf8fhCRRWldQW494/dEXleAhEFmzv/QrOWJ810bedluNWJnNe2OfoVNq58p0Z83BNgHhkNumSg8ClMiB+s6i0D04ELBB5k/jp3TaxIW9HKy5XvvF4LLQTa40APlInXYDkl+ELCdIXX6K3yVH9mcAaSkikTT9OKpWa35qCMW9rKHOzT39ipsZ1DMiARPIZuskxYdLu1l6M6SZmji4yBfi+ZyiGhQrtcQHISpZtBtmJf9t0tEQNBtq3cgnloOtAqvO7CJuVpSkrvg4A34pm9XXr7rEuF5NmOkfn+3M+EcmSQLT9Wy3amNzMQV9IaQry/Fg3kdM4TiClXJrG8vWLoNFvHA9kod1EoKBMyRbBlCQ7mtZWj/bN3pfRYZgO+3SX/RrPBrb8P7PTPNunhoW2m0C7/dpQdGSFcSacnqkDvhRRj3+9Ds94jIK4iZ6447bKY9Mo/PIO8ewAh/VUOxPyHz2PGBhDdTvWPc/abkKjq5Bw= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9186.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(366004)(376002)(136003)(39860400002)(396003)(346002)(83380400001)(478600001)(5660300002)(1076003)(36756003)(186003)(6486002)(2616005)(38350700002)(8936002)(86362001)(41300700001)(316002)(7416002)(6666004)(4326008)(8676002)(66476007)(38100700002)(66556008)(6506007)(6512007)(52116002)(2906002)(66946007)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?HubK25Iz1mN1lvmH/AMOd+gAQYP6?= =?utf-8?q?HIKmV8aE7IJsk6g+dH+tARPXJu1Ra72OxlfpnSD7qcHFaR8T9W87uaNxvB/FWKQHg?= =?utf-8?q?aen4803eabIjpCdHreisqYiSHm07qSpgwkLmIz0tZYf+jXs2bS3XG48klzHy3n83x?= =?utf-8?q?kREFAqDmkrkGfBDDypWxLiMwP5NkSLHS/tRwb8y+K/MPyoml4dC2xUcp7XoTt57fa?= =?utf-8?q?XEI7ejQOWU3zrgxBu8m5FOLVf8ySO80jAceJwem2xAZU6PuvEEfm5GjwM+T7XndwG?= =?utf-8?q?yx98HvoRKSAlxxGQx/zen2GxHRc7k4QhPJQLgLG7IMaIuqkIi9Y59fE8TYq3RNCTX?= =?utf-8?q?e4WD9LWikxTs8SeXQIGr+AJesvNn4UUFQzryNQf5eovG2+jSkHPwLLlrlHERSPdRT?= =?utf-8?q?G6itotbM9L9EOEo2CqVzT2Ag/T3ElyNoqVAZT72CbvnBfXvAUhLm/0xsPtuLQ/ls3?= =?utf-8?q?sGCzApGXEvTSvDhx+pXCVbEhlE1GnVeOaBmCERK200miYSX8U7Mh8xPVmlRBugXRo?= =?utf-8?q?kS3qzBVweg08Ydu8iPWpSGFEXt+7yMErHxwMVxUUmgZlFlrhsKwI64cxsWgvKhAKd?= =?utf-8?q?fcps0918HNdN4r8ZSUmfh5npMd/fty0HEcI/7245UWAcIEBJb9ADCvG8OpVd3KRiY?= =?utf-8?q?sBU6u4BX0D6/ESaJYkyUefKfYX41NaV3ZXSi2ih4o1EQlq/8lm2kehiaF6EbGdA+J?= =?utf-8?q?96iGNkKhFiusllUn1RmdLtAcPYcCR79i50etJoVKsccpk00p88UWs4U1etDbuWOZT?= =?utf-8?q?MWj4aO/o2SBBh+qc8Xu5Uwu3EfWmCjS+AnXZvbh6NHSQqHuOKEDioLG4JwDnlTdIC?= =?utf-8?q?OKjwsnGnnkdTVg2qAt0Xdaw96gqgQUhLsdXnR8gGJqDr7PKwLeR3opTXt5ykNgP+l?= =?utf-8?q?3N3g14AAu1OooCgi5XfDFLP1WSNPThuhJ33QLl2X1UVgQHfMdS+qVFC2nbadfnleY?= =?utf-8?q?iEBWwG1vi9iPiAX820vWXtlsmtq+X74reXBlPm2koRUctOZleaGj/KNpwljG6LeU6?= =?utf-8?q?r9/77V6PRiDvXTQOVuYwULrZrenLYOVJNImnlmfneJvqNHrPYsr9Kzj0EdeQ8b+Xd?= =?utf-8?q?cQW+bGvxpcrE30Pg6u8xM6bD5EkO3qTfex/8o2elUlTWxbN/9q3Z+2PSvLTNVqc1j?= =?utf-8?q?rTM7TtbFmNVZmRfoL1rRCKeaN18FW/msKnxRne83bnrhHlb4KKBHAJ4QzE3z2AuS/?= =?utf-8?q?By8HQsLrueV9yh0/SveQJX5kAx+t5F98jRvIkby8DbVDeXjRfSPZ3q6Htj8mpVX3e?= =?utf-8?q?Fl7N6ynBdg/5x6v2Cb9aESTH9aKnuKGlS3e70VVhMJUvSHBNr+ghN9LfrH9Poct4Z?= =?utf-8?q?3vgVK9Hv/BBXQxnZr98QoDxdW3Dfg4is8Hln1pKFB7VV09ITW3Z8kJnCpKX6y08H1?= =?utf-8?q?qr/22PdvNAHSvHCx9+/o3hH6kIv9B5H+toCOaTf2lTkSVzbquTJWMjpFJtpvkey6z?= =?utf-8?q?qpDvM5iJNAk6lpnfdb3fJChbsicCd8YpD2MUHcO1naGa3wJK2Rt/qJYzz6UxdMV3K?= =?utf-8?q?FkYwTGDOmmq6?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8a71fac6-145d-49f3-ae68-08da7f06be15 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9186.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2022 21:40:16.3844 (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: P/q4EVnQonnJtPAk6029ZoC4uMQ7z6LggR7Ps1GogxJTnrZo9PgyCfKl713xxHC1POuaBzeSElHSr7duHPneow== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0401MB2580 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220815_144021_182240_5C0509FE X-CRM114-Status: GOOD ( 21.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org ┌───────┐ ┌──────────┐ │ │ │ │ ┌─────────────┐ │ │ │ PCI Host │ │ MSI │◄┐ │ │ │ │ │ Controller │ │ │ │ │ │ └─────────────┘ └─┼───────┼──────────┼─BAR0 │ │ PCI │ │ BAR1 │ │ Func │ │ BAR2 │ │ │ │ BAR3 │ │ │ │ BAR4 │ │ ├─────────►│ │ └───────┘ └──────────┘ Linux supports endpoint functions. PCI Host write BAR space like write to memory. The EP side can't know memory changed by the host driver. PCI Spec has not defined a standard method to do that. Only define MSI(x) to let EP notified RC status change. The basic idea is to trigger an IRQ when PCI RC writes to a memory address. That's what MSI controller provided. EP drivers just need to request a platform MSI interrupt, struct msi_msg *msg will pass down a memory address and data. EP driver will map such memory address to one of PCI BAR. Host just writes such an address to trigger EP side irq. Add MSI support for pci-epf-vntb. pci-epf-vntb driver query if system have MSI controller. Setup doorbell address according to struct msi_msg. So PCIe host can write this doorbell address to triger EP side's irq. If no MSI controller exist, fall back to software polling. Signed-off-by: Frank Li --- drivers/pci/endpoint/functions/pci-epf-vntb.c | 134 +++++++++++++++--- 1 file changed, 112 insertions(+), 22 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c index 1466dd1904175..ad4f7ec8a39fc 100644 --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c @@ -44,6 +44,7 @@ #include #include #include +#include static struct workqueue_struct *kpcintb_workqueue; @@ -143,6 +144,8 @@ struct epf_ntb { void __iomem *vpci_mw_addr[MAX_MW]; struct delayed_work cmd_handler; + + int msi_virqbase; }; #define to_epf_ntb(epf_group) container_of((epf_group), struct epf_ntb, group) @@ -253,7 +256,7 @@ static void epf_ntb_cmd_handler(struct work_struct *work) ntb = container_of(work, struct epf_ntb, cmd_handler.work); - for (i = 1; i < ntb->db_count; i++) { + for (i = 1; i < ntb->db_count && !ntb->epf_db_phy; i++) { if (readl(ntb->epf_db + i * 4)) { if (readl(ntb->epf_db + i * 4)) ntb->db |= 1 << (i - 1); @@ -454,11 +457,9 @@ static int epf_ntb_config_spad_bar_alloc(struct epf_ntb *ntb) ctrl->num_mws = ntb->num_mws; ntb->spad_size = spad_size; - ctrl->db_entry_size = 4; - for (i = 0; i < ntb->db_count; i++) { ntb->reg->db_data[i] = 1 + i; - ntb->reg->db_offset[i] = 0; + ntb->reg->db_offset[i] = 4 * i; } return 0; @@ -509,6 +510,28 @@ static int epf_ntb_configure_interrupt(struct epf_ntb *ntb) return 0; } +static int epf_ntb_db_size(struct epf_ntb *ntb) +{ + const struct pci_epc_features *epc_features; + size_t size = 4 * ntb->db_count; + u32 align; + + epc_features = pci_epc_get_features(ntb->epf->epc, + ntb->epf->func_no, + ntb->epf->vfunc_no); + align = epc_features->align; + + if (size < 128) + size = 128; + + if (align) + size = ALIGN(size, align); + else + size = roundup_pow_of_two(size); + + return size; +} + /** * epf_ntb_db_bar_init() - Configure Doorbell window BARs * @ntb: NTB device that facilitates communication between HOST and vHOST @@ -520,35 +543,33 @@ static int epf_ntb_db_bar_init(struct epf_ntb *ntb) struct device *dev = &ntb->epf->dev; int ret; struct pci_epf_bar *epf_bar; - void __iomem *mw_addr; + void __iomem *mw_addr = NULL; enum pci_barno barno; - size_t size = 4 * ntb->db_count; + size_t size; epc_features = pci_epc_get_features(ntb->epf->epc, ntb->epf->func_no, ntb->epf->vfunc_no); align = epc_features->align; - - if (size < 128) - size = 128; - - if (align) - size = ALIGN(size, align); - else - size = roundup_pow_of_two(size); + size = epf_ntb_db_size(ntb); barno = ntb->epf_ntb_bar[BAR_DB]; + epf_bar = &ntb->epf->bar[barno]; - mw_addr = pci_epf_alloc_space(ntb->epf, size, barno, align, 0); - if (!mw_addr) { - dev_err(dev, "Failed to allocate OB address\n"); - return -ENOMEM; + if (!ntb->epf_db_phy) { + mw_addr = pci_epf_alloc_space(ntb->epf, size, barno, align, 0); + if (!mw_addr) { + dev_err(dev, "Failed to allocate OB address\n"); + return -ENOMEM; + } + } else { + epf_bar->phys_addr = ntb->epf_db_phy; + epf_bar->barno = barno; + epf_bar->size = size; } ntb->epf_db = mw_addr; - epf_bar = &ntb->epf->bar[barno]; - ret = pci_epc_set_bar(ntb->epf->epc, ntb->epf->func_no, ntb->epf->vfunc_no, epf_bar); if (ret) { dev_err(dev, "Doorbell BAR set failed\n"); @@ -704,6 +725,74 @@ static int epf_ntb_init_epc_bar(struct epf_ntb *ntb) return 0; } +static void epf_ntb_write_msi_msg(struct msi_desc *desc, struct msi_msg *msg) +{ + struct epf_ntb *ntb = dev_get_drvdata(desc->dev); + struct epf_ntb_ctrl *reg = ntb->reg; + int size = epf_ntb_db_size(ntb); + u64 addr; + + addr = msg->address_hi; + addr <<= 32; + addr |= msg->address_lo; + + reg->db_data[desc->msi_index] = msg->data; + + if (desc->msi_index == 0) + ntb->epf_db_phy = round_down(addr, size); + + reg->db_offset[desc->msi_index] = addr - ntb->epf_db_phy; +} + +static irqreturn_t epf_ntb_interrupt_handler(int irq, void *data) +{ + struct epf_ntb *ntb = data; + int index; + + index = irq - ntb->msi_virqbase; + ntb->db |= 1 << (index - 1); + ntb_db_event(&ntb->ntb, index); + + return IRQ_HANDLED; +} + +static void epf_ntb_epc_msi_init(struct epf_ntb *ntb) +{ + struct device *dev = &ntb->epf->dev; + struct irq_domain *domain; + int virq; + int ret; + int i; + + domain = dev_get_msi_domain(ntb->epf->epc->dev.parent); + if (!domain) + return; + + dev_set_msi_domain(dev, domain); + + if (platform_msi_domain_alloc_irqs(&ntb->epf->dev, + ntb->db_count, + epf_ntb_write_msi_msg)) { + dev_info(dev, "Can't allocate MSI, fall back to poll mode\n"); + return; + } + + dev_info(dev, "vntb use MSI as doorbell\n"); + + for (i = 0; i < ntb->db_count; i++) { + virq = msi_get_virq(dev, i); + ret = devm_request_irq(dev, virq, + epf_ntb_interrupt_handler, 0, + "ntb", ntb); + + if (ret) + dev_err(dev, "devm_request_irq() failure\n"); + + if (!i) + ntb->msi_virqbase = virq; + } +} + /** * epf_ntb_epc_init() - Initialize NTB interface * @ntb: NTB device that facilitates communication between HOST and vHOST2 @@ -1299,14 +1388,15 @@ static int epf_ntb_bind(struct pci_epf *epf) goto err_bar_alloc; } + epf_set_drvdata(epf, ntb); + epf_ntb_epc_msi_init(ntb); + ret = epf_ntb_epc_init(ntb); if (ret) { dev_err(dev, "Failed to initialize EPC\n"); goto err_bar_alloc; } - epf_set_drvdata(epf, ntb); - pci_space[0] = (ntb->vntb_pid << 16) | ntb->vntb_vid; pci_vntb_table[0].vendor = ntb->vntb_vid; pci_vntb_table[0].device = ntb->vntb_pid;