linux-fpga.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wu Hao <hao.wu@intel.com>
To: Xu Yilun <yilun.xu@intel.com>
Cc: mdf@kernel.org, linux-fpga@vger.kernel.org,
	linux-kernel@vger.kernel.org, Luwei Kang <luwei.kang@intel.com>
Subject: Re: [PATCH 2/7] fpga: dfl: pci: add irq info for feature devices enumeration
Date: Tue, 10 Mar 2020 18:26:33 +0800	[thread overview]
Message-ID: <20200310102633.GB28396@hao-dev> (raw)
In-Reply-To: <20200310094143.GB30868@yilunxu-OptiPlex-7050>

On Tue, Mar 10, 2020 at 05:41:43PM +0800, Xu Yilun wrote:
> On Tue, Mar 10, 2020 at 10:46:26AM +0800, Wu Hao wrote:
> > Hi Yilun
> > 
> > Some comments inline. : )
> > 
> > On Mon, Mar 09, 2020 at 06:29:45PM +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 <luwei.kang@intel.com>
> > > Signed-off-by: Wu Hao <hao.wu@intel.com>
> > > Signed-off-by: Xu Yilun <yilun.xu@intel.com>
> > > ---
> > >  drivers/fpga/dfl-pci.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++----
> > >  1 file changed, 61 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/drivers/fpga/dfl-pci.c b/drivers/fpga/dfl-pci.c
> > > index 5387550..a3370e5 100644
> > > --- a/drivers/fpga/dfl-pci.c
> > > +++ b/drivers/fpga/dfl-pci.c
> > > @@ -80,8 +80,23 @@ static void cci_remove_feature_devs(struct pci_dev *pcidev)
> > >  	dfl_fpga_feature_devs_remove(drvdata->cdev);
> > >  }
> > >  
> > > +static int *cci_pci_create_irq_table(struct pci_dev *pcidev, unsigned int nvec)
> > > +{
> > > +	int *table, i;
> > > +
> > > +	table = kcalloc(nvec, sizeof(int), GFP_KERNEL);
> > 
> > Maybe devm_ version is better?
> 
> This table will be freed right after dfl_fpga_enum_info_add_irq(). Maybe
> don't need devm_ version.
> 
> > 
> > > +	if (!table)
> > > +		return NULL;
> > > +
> > > +	for (i = 0; i < nvec; i++)
> > 
> > i should be unsigned int as well?
> 
> Yes I should change it.
> 
> > 
> > > +		table[i] = pci_irq_vector(pcidev, i);

Hi Yilun,

one more place here.


table = kcalloc(nevc, sizeof(int), GFP_KERNEL);
if (table) {
	...
}	

return table;

Thanks
Hao

> > > +
> > > +	return table;
> > > +}
> > > +
> > >  /* enumerate feature devices under pci device */
> > > -static int cci_enumerate_feature_devs(struct pci_dev *pcidev)
> > > +static int cci_enumerate_feature_devs(struct pci_dev *pcidev,
> > > +				      unsigned int nvec)
> > >  {
> > >  	struct cci_drvdata *drvdata = pci_get_drvdata(pcidev);
> > >  	struct dfl_fpga_enum_info *info;
> > > @@ -89,6 +104,7 @@ static int cci_enumerate_feature_devs(struct pci_dev *pcidev)
> > >  	resource_size_t start, len;
> > >  	int port_num, bar, i, ret = 0;
> > >  	void __iomem *base;
> > > +	int *irq_table;
> > >  	u32 offset;
> > >  	u64 v;
> > >  
> > > @@ -97,6 +113,18 @@ static int cci_enumerate_feature_devs(struct pci_dev *pcidev)
> > >  	if (!info)
> > >  		return -ENOMEM;
> > >  
> > > +	/* add irq info for enumeration if really needed */
> > > +	if (nvec) {
> > > +		irq_table = cci_pci_create_irq_table(pcidev, nvec);
> > > +		if (irq_table) {
> > > +			dfl_fpga_enum_info_add_irq(info, nvec, irq_table);
> > > +			kfree(irq_table);
> > > +		} else {
> > > +			ret = -ENOMEM;
> > > +			goto enum_info_free_exit;
> > > +		}
> > > +	}
> > > +
> > >  	/* start to find Device Feature List from Bar 0 */
> > >  	base = cci_pci_ioremap_bar(pcidev, 0);
> > >  	if (!base) {
> > > @@ -173,6 +201,28 @@ static int cci_enumerate_feature_devs(struct pci_dev *pcidev)
> > >  	return ret;
> > >  }
> > >  
> > > +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);
> > > +}
> > > +
> > >  static
> > >  int cci_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pcidevid)
> > >  {
> > > @@ -210,14 +260,19 @@ int cci_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pcidevid)
> > >  		goto disable_error_report_exit;
> > >  	}
> > >  
> > > -	ret = cci_enumerate_feature_devs(pcidev);
> > > -	if (ret) {
> > > -		dev_err(&pcidev->dev, "enumeration failure %d.\n", ret);
> > > +	ret = cci_pci_alloc_irq(pcidev);
> > > +	if (ret < 0) {
> > > +		dev_err(&pcidev->dev, "Fail to alloc irq %d.\n", ret);
> > 
> > we prepare mmio resources in side cci_enumerate_feature_devs.
> > 
> > maybe we could put irq resources code in side cce_enumerate_feature_devs too?
> 
> Yes I will try to change it in patch v2.
> 
> Thanks for your quick response.
> 
> > 
> > 
> > Thanks
> > Hao
> > 
> > >  		goto disable_error_report_exit;
> > >  	}
> > >  
> > > -	return ret;
> > > +	ret = cci_enumerate_feature_devs(pcidev, (unsigned int)ret);
> > > +	if (!ret)
> > > +		return ret;
> > > +
> > > +	dev_err(&pcidev->dev, "enumeration failure %d.\n", ret);
> > >  
> > > +	cci_pci_free_irq(pcidev);
> > >  disable_error_report_exit:
> > >  	pci_disable_pcie_error_reporting(pcidev);
> > >  	return ret;
> > > @@ -263,6 +318,7 @@ static void cci_pci_remove(struct pci_dev *pcidev)
> > >  		cci_pci_sriov_configure(pcidev, 0);
> > >  
> > >  	cci_remove_feature_devs(pcidev);
> > > +	cci_pci_free_irq(pcidev);
> > >  	pci_disable_pcie_error_reporting(pcidev);
> > >  }
> > >  
> > > -- 
> > > 2.7.4

  reply	other threads:[~2020-03-10 10:26 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-09 10:29 [PATCH 0/7] Add interrupt support to FPGA DFL drivers Xu Yilun
2020-03-09 10:29 ` [PATCH 1/7] fpga: dfl: parse interrupt info for feature devices on enumeration Xu Yilun
2020-03-10  2:26   ` Wu Hao
2020-03-10  9:25     ` Xu Yilun
2020-03-10 10:21       ` Wu Hao
2020-03-09 10:29 ` [PATCH 2/7] fpga: dfl: pci: add irq info for feature devices enumeration Xu Yilun
2020-03-10  2:46   ` Wu Hao
2020-03-10  9:41     ` Xu Yilun
2020-03-10 10:26       ` Wu Hao [this message]
2020-03-09 10:29 ` [PATCH 3/7] fpga: dfl: introduce interrupt trigger setting API Xu Yilun
2020-03-10 10:30   ` Wu Hao
2020-03-11  2:14     ` Xu Yilun
2020-03-09 10:29 ` [PATCH 4/7] fpga: dfl: afu: add interrupt support for error reporting Xu Yilun
2020-03-10 10:39   ` Wu Hao
2020-03-10 16:47     ` Xu Yilun
2020-03-11  2:43       ` Wu Hao
2020-03-11  6:35         ` Xu Yilun
2020-03-09 10:29 ` [PATCH 5/7] fpga: dfl: fme: add interrupt support for global " Xu Yilun
2020-03-09 10:29 ` [PATCH 6/7] fpga: dfl: afu: add user interrupt support Xu Yilun
2020-03-09 10:29 ` [PATCH 7/7] Documentation: fpga: dfl: add descriptions for interrupt related interfaces Xu Yilun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200310102633.GB28396@hao-dev \
    --to=hao.wu@intel.com \
    --cc=linux-fpga@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luwei.kang@intel.com \
    --cc=mdf@kernel.org \
    --cc=yilun.xu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).