Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4599064ybb; Tue, 24 Mar 2020 01:36:02 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuW9CkH+hVb+YRqFqDsrMk9mFtTgog9F8eXS7/biItMMgG2xa2mOhjSFzjqPkagS1/kJ/mg X-Received: by 2002:a05:6808:18b:: with SMTP id w11mr191842oic.94.1585038962687; Tue, 24 Mar 2020 01:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585038962; cv=none; d=google.com; s=arc-20160816; b=fE8m8jVIdvR0PHmy9WSDkajtI6RVDu7MlfIh938R7Hf08MOmq74IfimXbok8A2/EQY IApk1j15HaZNLtZEkAe6lhkFZ5JhdsPF6EJcWL9aHWy5Ix5j0wXm0phmkqcmm2NGThZM CFPwT9UPk+NXzHScBZ8/be9k779Av1XTTnS2+FGq1lKQYvVyUmhQP3gYYh2WJjD4iW9S 4y4Z8KecOy1V6PuvzJtT3qMYyVyJMg9q8vo6ny2yxz5QUcVWIG5sh0kEUSOEpJFRDIuy 79Mqnk/MW+W6WwueQHoghAY9kAI6woSAvEh16Tv/RQRf3VOcfsUDQA2aFbCRJIZYK1xc bsUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:ironport-sdr:ironport-sdr; bh=tbBgtpXbL16tStvwDOhryl4xh6tBG21dldH4iYep8kg=; b=O8/XulhQScwfcrkyDr/iwvDQW7j79A/kM5J0QLGHlrTpGp9BT1fp7MRKa4D3godf6h xiZe0ky3aYbvHiXqrAx4ahhUqXDG3oXWm7ZyPUnZVQXcAwrFtb3fa1EU7IdUTwL7emMF WXryObkLl4J4WoSIzuRc27VoNigWe1HNfGwxdKb4EN8YF3amW0hkASjoswgpE/E1A2if 6uMzTbQRJYZ4ZQWNmNb0xvInXZ36lE3a96eAkt+Cwk/CAp3lufc7eoN1UHh6aQFINvzC Z1akezd7AbeDzo8wdyzBdfDvheWi2lXbMo4p5tEgB4y52SfiIfzMIqmVv2QD8TEI/BaR cpFg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i21si2558602otc.183.2020.03.24.01.35.50; Tue, 24 Mar 2020 01:36:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727137AbgCXIf2 (ORCPT + 99 others); Tue, 24 Mar 2020 04:35:28 -0400 Received: from mga03.intel.com ([134.134.136.65]:53578 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727112AbgCXIf1 (ORCPT ); Tue, 24 Mar 2020 04:35:27 -0400 IronPort-SDR: pFWRZoi2Zi5QXDn3j0SrAKjaKwDey/swzpjxB7+JkwuC8Bf+1JS8U8nM2q/j1u4lHQrbB5yYfe XFF/K4qbe7bA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2020 01:35:27 -0700 IronPort-SDR: z9SgiUoME+1+8g23oECl6v6vb9Pru72xU5/zXeRQS3oVC3v4z/2MLWbhnaPvQ3HFJYIuqjhqg9 UcFvkpGw5dXQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,299,1580803200"; d="scan'208";a="446143781" Received: from yilunxu-optiplex-7050.sh.intel.com ([10.239.159.141]) by fmsmga005.fm.intel.com with ESMTP; 24 Mar 2020 01:35:24 -0700 From: Xu Yilun To: mdf@kernel.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Cc: trix@redhat.com, bhu@redhat.com, Xu Yilun , Luwei Kang , Wu Hao Subject: [PATCH v3 2/7] fpga: dfl: pci: add irq info for feature devices enumeration Date: Tue, 24 Mar 2020 16:32:38 +0800 Message-Id: <1585038763-22944-3-git-send-email-yilun.xu@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1585038763-22944-1-git-send-email-yilun.xu@intel.com> References: <1585038763-22944-1-git-send-email-yilun.xu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some DFL FPGA PCIe cards (e.g. Intel FPGA Programmable Acceleration Card) support MSI-X based interrupts. This patch allows PCIe driver to prepare and pass interrupt resources to DFL via enumeration API. These interrupt resources could then be assigned to actual features which use them. Signed-off-by: Luwei Kang Signed-off-by: Wu Hao Signed-off-by: Xu Yilun ---- v2: put irq resources init code inside cce_enumerate_feature_dev() Some minor changes for Hao's comments. v3: Some minor fix for Hao's comments for v2. --- drivers/fpga/dfl-pci.c | 76 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 9 deletions(-) diff --git a/drivers/fpga/dfl-pci.c b/drivers/fpga/dfl-pci.c index 5387550..66027aa 100644 --- a/drivers/fpga/dfl-pci.c +++ b/drivers/fpga/dfl-pci.c @@ -39,6 +39,28 @@ static void __iomem *cci_pci_ioremap_bar(struct pci_dev *pcidev, int bar) return pcim_iomap_table(pcidev)[bar]; } +static int cci_pci_alloc_irq(struct pci_dev *pcidev) +{ + int nvec = pci_msix_vec_count(pcidev); + int ret; + + if (nvec <= 0) { + dev_dbg(&pcidev->dev, "fpga interrupt not supported\n"); + return 0; + } + + ret = pci_alloc_irq_vectors(pcidev, nvec, nvec, PCI_IRQ_MSIX); + if (ret < 0) + return ret; + + return nvec; +} + +static void cci_pci_free_irq(struct pci_dev *pcidev) +{ + pci_free_irq_vectors(pcidev); +} + /* PCI Device ID */ #define PCIE_DEVICE_ID_PF_INT_5_X 0xBCBD #define PCIE_DEVICE_ID_PF_INT_6_X 0xBCC0 @@ -78,17 +100,33 @@ static void cci_remove_feature_devs(struct pci_dev *pcidev) /* remove all children feature devices */ dfl_fpga_feature_devs_remove(drvdata->cdev); + cci_pci_free_irq(pcidev); +} + +static int *cci_pci_create_irq_table(struct pci_dev *pcidev, unsigned int nvec) +{ + unsigned int i; + int *table; + + table = kcalloc(nvec, sizeof(int), GFP_KERNEL); + if (table) { + for (i = 0; i < nvec; i++) + table[i] = pci_irq_vector(pcidev, i); + } + + return table; } /* enumerate feature devices under pci device */ static int cci_enumerate_feature_devs(struct pci_dev *pcidev) { struct cci_drvdata *drvdata = pci_get_drvdata(pcidev); + int port_num, bar, i, nvec, ret = 0; struct dfl_fpga_enum_info *info; struct dfl_fpga_cdev *cdev; resource_size_t start, len; - int port_num, bar, i, ret = 0; void __iomem *base; + int *irq_table; u32 offset; u64 v; @@ -97,11 +135,30 @@ static int cci_enumerate_feature_devs(struct pci_dev *pcidev) if (!info) return -ENOMEM; + /* add irq info for enumeration if the device support irq */ + nvec = cci_pci_alloc_irq(pcidev); + if (nvec < 0) { + dev_err(&pcidev->dev, "Fail to alloc irq %d.\n", nvec); + ret = nvec; + goto enum_info_free_exit; + } else if (nvec) { + irq_table = cci_pci_create_irq_table(pcidev, nvec); + if (!irq_table) { + ret = -ENOMEM; + goto irq_free_exit; + } + + ret = dfl_fpga_enum_info_add_irq(info, nvec, irq_table); + kfree(irq_table); + if (ret) + goto irq_free_exit; + } + /* start to find Device Feature List from Bar 0 */ base = cci_pci_ioremap_bar(pcidev, 0); if (!base) { ret = -ENOMEM; - goto enum_info_free_exit; + goto irq_free_exit; } /* @@ -154,7 +211,7 @@ static int cci_enumerate_feature_devs(struct pci_dev *pcidev) dfl_fpga_enum_info_add_dfl(info, start, len, base); } else { ret = -ENODEV; - goto enum_info_free_exit; + goto irq_free_exit; } /* start enumeration with prepared enumeration information */ @@ -162,11 +219,14 @@ static int cci_enumerate_feature_devs(struct pci_dev *pcidev) if (IS_ERR(cdev)) { dev_err(&pcidev->dev, "Enumeration failure\n"); ret = PTR_ERR(cdev); - goto enum_info_free_exit; + goto irq_free_exit; } drvdata->cdev = cdev; +irq_free_exit: + if (ret) + cci_pci_free_irq(pcidev); enum_info_free_exit: dfl_fpga_enum_info_free(info); @@ -211,12 +271,10 @@ int cci_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pcidevid) } ret = cci_enumerate_feature_devs(pcidev); - if (ret) { - dev_err(&pcidev->dev, "enumeration failure %d.\n", ret); - goto disable_error_report_exit; - } + if (!ret) + return ret; - return ret; + dev_err(&pcidev->dev, "enumeration failure %d.\n", ret); disable_error_report_exit: pci_disable_pcie_error_reporting(pcidev); -- 2.7.4