Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3137433ybb; Mon, 30 Mar 2020 22:05:01 -0700 (PDT) X-Google-Smtp-Source: ADFU+vszMAUzs8Vslq3ekoiI7if2TuJ6TLUhSvObf0k/yxvn2paNnBr4v7R06igRZcHJgSP0cPNV X-Received: by 2002:a9d:2004:: with SMTP id n4mr2046640ota.74.1585631100954; Mon, 30 Mar 2020 22:05:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585631100; cv=none; d=google.com; s=arc-20160816; b=rqaJSx0t6yYFI3NmK+Z0J0RaHi4yeDItxOKfmkhns/8rTdafs+K69mQE23rhoDANpv zO2L7PKq4FVYOembjw+WROIOB0bf0WajUn/k0Wib0UQU+Vv29SpmjUioEQ0URJi3sS55 77poFk8+/Rx1TSqVDbBZA7e1soARdxA00fpNQvikFAW/jakR0NCXD3kN63ZpnJFafcE3 eTXE9vyOwQpptd2R9gBWPyhoeoIac492AHUC5/WUtp/F2B7AlD37qoI8WxHqkoykKuHF E+ktUaBD8ECd73B3MWZwsu4MrjioFBmH6B1e3bZn2Ac5tj0srSUsJ8Q4BmaWWwud2Hww RL4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=OvAE51ywYNkhD0NuPEhh+Oqm/0ple+dqs4wne7Apo7U=; b=BtBwNDiniyV7V+ZQ1yuSZlcHQoDw/6EVr/gyuMBr7Npgt/pEXBKLUJmlDUk+cbFlho vsKj4zblaDBk4Dp5Brgq8I+oPCc1BUhtHpBOZ82XAEBnFk6sp4l7ddlJAGEWzNaeZS+A 6wxP+GELlDWm0cV3vp2O7v3GtFr6ZN/2LMvfeBgYnQSNuMYZGVf5/0gErL5n8vTEk+kX Wq2MxRE2IprZLRMGw/5y813+BxdXB0VKNP9lytiYrOom9AUV1JKzL9/Kj7dxedeYqlGR cl0u2tRLIdhLCZMgCr/MqSMveYY/pzgGsHKAd5ul1+6mZ13iF/6eYdO3kAIxsdh+e3Px VihA== 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 k92si7497729otk.261.2020.03.30.22.04.11; Mon, 30 Mar 2020 22:05:00 -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 S1726393AbgCaFCj (ORCPT + 99 others); Tue, 31 Mar 2020 01:02:39 -0400 Received: from mga11.intel.com ([192.55.52.93]:42556 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725809AbgCaFCj (ORCPT ); Tue, 31 Mar 2020 01:02:39 -0400 IronPort-SDR: bP8VyzM41dR65H9mjT/N2rXOMgQUUt0CnZkQSJlN8ZMfjQmQhvTL3ixonSDnXXm+ALrQ4ibpIl m+p6leDaCu5w== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2020 22:02:38 -0700 IronPort-SDR: SGkY7AcNeGoks8wjIxO5mQBYElSn5rlPxXqNNGZg787AlYtih96yaAWeKcJlZwXdML1UUJZrpy HsqY7Tzjvu2A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="267158195" Received: from hao-dev.bj.intel.com (HELO localhost) ([10.238.157.65]) by orsmga002.jf.intel.com with ESMTP; 30 Mar 2020 22:02:36 -0700 Date: Tue, 31 Mar 2020 12:41:20 +0800 From: Wu Hao To: Xu Yilun Cc: mdf@kernel.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org, trix@redhat.com, bhu@redhat.com, Luwei Kang Subject: Re: [PATCH v3 2/7] fpga: dfl: pci: add irq info for feature devices enumeration Message-ID: <20200331044120.GB8468@hao-dev> References: <1585038763-22944-1-git-send-email-yilun.xu@intel.com> <1585038763-22944-3-git-send-email-yilun.xu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1585038763-22944-3-git-send-email-yilun.xu@intel.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 24, 2020 at 04:32:38PM +0800, Xu Yilun wrote: > 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; maybe int ret, nvec = pci_msix.. > + > + 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); i see you create a function for cci_pci_free_irq instead of using kernel api directly, to make it more readable, so why not have a remove irq table function here too. Actually patch looks good to me, with above minor fixes. Acked-by: Wu Hao Hao > + 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