linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wei Yang <weiyang@linux.vnet.ibm.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: Wei Yang <weiyang@linux.vnet.ibm.com>,
	benh@au1.ibm.com, gwshan@linux.vnet.ibm.com,
	linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH V11 13/17] powerpc/powernv: Implement pcibios_iov_resource_alignment() on powernv
Date: Thu, 5 Feb 2015 06:45:40 +0800	[thread overview]
Message-ID: <20150204224540.GA18037@richard> (raw)
In-Reply-To: <20150204212614.GB11271@google.com>

On Wed, Feb 04, 2015 at 03:26:14PM -0600, Bjorn Helgaas wrote:
>On Thu, Jan 15, 2015 at 10:28:03AM +0800, Wei Yang wrote:
>> This patch implements the pcibios_iov_resource_alignment() on powernv
>> platform.
>> 
>> On PowerNV platform, there are 3 cases for the IOV BAR:
>> 1. initial state, the IOV BAR size is multiple times of VF BAR size
>> 2. after expanded, the IOV BAR size is expanded to meet the M64 segment size
>> 3. sizing stage, the IOV BAR is truncated to 0
>> 
>> pnv_pci_iov_resource_alignment() handle these three cases respectively.
>>
>> Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com>
>> ---
>>  arch/powerpc/include/asm/machdep.h        |    3 +++
>>  arch/powerpc/kernel/pci-common.c          |   14 ++++++++++++++
>>  arch/powerpc/platforms/powernv/pci-ioda.c |   20 ++++++++++++++++++++
>>  3 files changed, 37 insertions(+)
>> 
>> diff --git a/arch/powerpc/include/asm/machdep.h b/arch/powerpc/include/asm/machdep.h
>> index 965547c..12e8eb8 100644
>> --- a/arch/powerpc/include/asm/machdep.h
>> +++ b/arch/powerpc/include/asm/machdep.h
>> @@ -252,6 +252,9 @@ struct machdep_calls {
>>  
>>  #ifdef CONFIG_PCI_IOV
>>  	void (*pcibios_fixup_sriov)(struct pci_bus *bus);
>> +	resource_size_t (*pcibios_iov_resource_alignment)(struct pci_dev *,
>> +			                                    int resno,
>> +							    resource_size_t align);
>>  #endif /* CONFIG_PCI_IOV */
>>  
>>  	/* Called to shutdown machine specific hardware not already controlled
>> diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
>> index 832b7e1..8751dfb 100644
>> --- a/arch/powerpc/kernel/pci-common.c
>> +++ b/arch/powerpc/kernel/pci-common.c
>> @@ -130,6 +130,20 @@ void pcibios_reset_secondary_bus(struct pci_dev *dev)
>>  	pci_reset_secondary_bus(dev);
>>  }
>>  
>> +#ifdef CONFIG_PCI_IOV
>> +resource_size_t pcibios_iov_resource_alignment(struct pci_dev *pdev,
>> +						 int resno,
>> +						 resource_size_t align)
>> +{
>> +	if (ppc_md.pcibios_iov_resource_alignment)
>> +		return ppc_md.pcibios_iov_resource_alignment(pdev,
>> +							       resno,
>> +							       align);
>> +
>> +	return 0;
>
>This isn't right, is it?  The default (weak) version returns
>pci_iov_resource_size(dev, resno).  When you don't have a
>ppc_md.pcibios_iov_resource_alignment pointer, don't you
>want to do that, too?
>

You are right, this isn't correct.

It should return align here.

>> +}
>> +#endif /* CONFIG_PCI_IOV */
>> +
>>  static resource_size_t pcibios_io_size(const struct pci_controller *hose)
>>  {
>>  #ifdef CONFIG_PPC64
>> diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
>> index 6704fdf..8bad2b0 100644
>> --- a/arch/powerpc/platforms/powernv/pci-ioda.c
>> +++ b/arch/powerpc/platforms/powernv/pci-ioda.c
>> @@ -1953,6 +1953,25 @@ static resource_size_t pnv_pci_window_alignment(struct pci_bus *bus,
>>  	return phb->ioda.io_segsize;
>>  }
>>  
>> +#ifdef CONFIG_PCI_IOV
>> +static resource_size_t pnv_pci_iov_resource_alignment(struct pci_dev *pdev,
>> +							    int resno,
>> +							    resource_size_t align)
>> +{
>> +	struct pci_dn *pdn = pci_get_pdn(pdev);
>> +	resource_size_t iov_align;
>> +
>> +	iov_align = resource_size(&pdev->resource[resno]);
>> +	if (iov_align)
>> +		return iov_align;
>> +
>> +	if (pdn->max_vfs)
>> +		return pdn->max_vfs * align;
>> +
>> +	return align;
>
>pcibios_iov_resource_alignment() returns different things depending on when
>you call it?  That doesn't sound good.
>

Agree, this is not a good way to address this problem.

>Is this related to my questions about sriov_init() and
>pnv_pci_ioda_fixup_iov_resources()?  If you adopted my suggestion and set
>the size once in sriov_init(), would that get rid of one of these cases?
>
>Maybe it would help me understand if you explained the three cases a bit
>more.

Sure, and this helps me too :)

First pci_sriov_resource_alignment() returns the single VF BAR size in the
original version. And the purpose for introducing the
pcibios_iov_resource_alignment() is to give arch a chance to return different
value. For powernv platform, we want to return the 256 * single VF BAR size.

This size is used in the pbus_size_mem() for sizing stage and in
pci_assign_unassigned_root_bus_resources() for assigning stage. Normally, on
powernv platform, it just need to return the resource_size() of this IOV BAR,
while there is a problem in pci_assign_unassigned_root_bus_resources().

Since the IOV BAR is an "additional" resource, in pbus_size_mem() the resource
will be truncated to 0. So the first case will fail. And the size needs to be
calculated from the max_vfs * VF BAR size.

max_vfs is field in pci_dn, which may not be set before the fixup is called.
Even currently I don't see someone ask for IOV BAR alignment before fixup, I
am not sure in the future no one will do this.  I believe you method mentioned
in another mail will solve this problem. This means when sriov_init() returns,
we get the exact number of VF BAR size it reseved.

The last case is to make the logic tight. In case both the above two cases
fails, this will return the original value.

I believe after using your proposed method, to "fixup" the IOV BAR in
sriov_init(), we could just return the max_vfs * VF BAR size.

>
>> +}
>> +#endif /* CONFIG_PCI_IOV */
>> +
>>  /* Prevent enabling devices for which we couldn't properly
>>   * assign a PE
>>   */
>> @@ -2155,6 +2174,7 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
>>  	ppc_md.pcibios_reset_secondary_bus = pnv_pci_reset_secondary_bus;
>>  #ifdef CONFIG_PCI_IOV
>>  	ppc_md.pcibios_fixup_sriov = pnv_pci_ioda_fixup_sriov;
>> +	ppc_md.pcibios_iov_resource_alignment = pnv_pci_iov_resource_alignment;
>>  #endif /* CONFIG_PCI_IOV */
>>  	pci_add_flags(PCI_REASSIGN_ALL_RSRC);
>>  
>> -- 
>> 1.7.9.5
>> 
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>--
>To unsubscribe from this list: send the line "unsubscribe linux-pci" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Richard Yang
Help you, Help me


  reply	other threads:[~2015-02-04 22:46 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-22  5:54 [PATCH V10 00/17] Enable SRIOV on Power8 Wei Yang
2014-12-22  5:54 ` [PATCH V10 01/17] PCI/IOV: Export interface for retrieve VF's BDF Wei Yang
2014-12-22  5:54 ` [PATCH V10 02/17] PCI/IOV: add VF enable/disable hook Wei Yang
2014-12-22  5:54 ` [PATCH V10 03/17] PCI: Add weak pcibios_iov_resource_alignment() interface Wei Yang
2014-12-22  5:54 ` [PATCH V10 04/17] PCI: Store VF BAR size in pci_sriov Wei Yang
2014-12-22  5:54 ` [PATCH V10 05/17] PCI: Take additional PF's IOV BAR alignment in sizing and assigning Wei Yang
2014-12-22  5:54 ` [PATCH V10 06/17] powerpc/pci: Add PCI resource alignment documentation Wei Yang
2014-12-22  5:54 ` [PATCH V10 07/17] powerpc/pci: Don't unset pci resources for VFs Wei Yang
2014-12-22  5:54 ` [PATCH V10 08/17] powrepc/pci: Refactor pci_dn Wei Yang
2014-12-22  5:54 ` [PATCH V10 09/17] powerpc/pci: remove pci_dn->pcidev field Wei Yang
2014-12-22  5:54 ` [PATCH V10 10/17] powerpc/powernv: Use pci_dn in PCI config accessor Wei Yang
2014-12-22  5:54 ` [PATCH V10 11/17] powerpc/powernv: Allocate pe->iommu_table dynamically Wei Yang
2014-12-22  5:54 ` [PATCH V10 12/17] powerpc/powernv: Reserve additional space for IOV BAR according to the number of total_pe Wei Yang
2014-12-22  5:54 ` [PATCH V10 13/17] powerpc/powernv: Implement pcibios_iov_resource_alignment() on powernv Wei Yang
2014-12-22  5:54 ` [PATCH V10 14/17] powerpc/powernv: Shift VF resource with an offset Wei Yang
2014-12-22  5:54 ` [PATCH V10 15/17] powerpc/powernv: Allocate VF PE Wei Yang
2014-12-22  5:54 ` [PATCH V10 16/17] powerpc/powernv: Reserve additional space for IOV BAR, with m64_per_iov supported Wei Yang
2014-12-22  5:54 ` [PATCH V10 17/17] powerpc/powernv: Group VF PE when IOV BAR is big on PHB3 Wei Yang
2014-12-22  6:05 ` [PATCH V10 00/17] Enable SRIOV on Power8 Wei Yang
2015-01-13 18:05   ` Bjorn Helgaas
2015-01-15  2:27     ` [PATCH V11 " Wei Yang
2015-01-15  2:27       ` [PATCH V11 01/17] PCI/IOV: Export interface for retrieve VF's BDF Wei Yang
2015-02-20 23:09         ` Bjorn Helgaas
2015-03-02  6:05           ` Wei Yang
2015-01-15  2:27       ` [PATCH V11 02/17] PCI/IOV: add VF enable/disable hook Wei Yang
2015-02-10  0:26         ` Benjamin Herrenschmidt
2015-02-10  1:35           ` Wei Yang
2015-02-10  2:13             ` Benjamin Herrenschmidt
2015-02-10  6:18               ` Wei Yang
2015-01-15  2:27       ` [PATCH V11 03/17] PCI: Add weak pcibios_iov_resource_alignment() interface Wei Yang
2015-02-10  0:32         ` Benjamin Herrenschmidt
2015-02-10  1:44           ` Wei Yang
2015-01-15  2:27       ` [PATCH V11 04/17] PCI: Store VF BAR size in pci_sriov Wei Yang
2015-01-15  2:27       ` [PATCH V11 05/17] PCI: Take additional PF's IOV BAR alignment in sizing and assigning Wei Yang
2015-01-15  2:27       ` [PATCH V11 06/17] powerpc/pci: Add PCI resource alignment documentation Wei Yang
2015-02-04 23:44         ` Bjorn Helgaas
2015-02-10  1:02           ` Benjamin Herrenschmidt
2015-02-20  0:56             ` Bjorn Helgaas
2015-02-20  2:41               ` Benjamin Herrenschmidt
2015-01-15  2:27       ` [PATCH V11 07/17] powerpc/pci: Don't unset pci resources for VFs Wei Yang
2015-02-10  0:36         ` Benjamin Herrenschmidt
2015-02-10  1:51           ` Wei Yang
2015-02-10  2:14             ` Benjamin Herrenschmidt
2015-02-10  6:25               ` Wei Yang
2015-02-10  8:14                 ` Benjamin Herrenschmidt
2015-02-20 23:47                   ` Bjorn Helgaas
2015-03-02  6:09                     ` Wei Yang
2015-01-15  2:27       ` [PATCH V11 08/17] powrepc/pci: Refactor pci_dn Wei Yang
2015-02-20 23:19         ` Bjorn Helgaas
2015-02-23  0:13           ` Gavin Shan
2015-02-24  8:13             ` Bjorn Helgaas
2015-02-24  8:25               ` Benjamin Herrenschmidt
2015-01-15  2:27       ` [PATCH V11 09/17] powerpc/pci: remove pci_dn->pcidev field Wei Yang
2015-01-15  2:28       ` [PATCH V11 10/17] powerpc/powernv: Use pci_dn in PCI config accessor Wei Yang
2015-01-15  2:28       ` [PATCH V11 11/17] powerpc/powernv: Allocate pe->iommu_table dynamically Wei Yang
2015-01-15  2:28       ` [PATCH V11 12/17] powerpc/powernv: Reserve additional space for IOV BAR according to the number of total_pe Wei Yang
2015-02-04 21:26         ` Bjorn Helgaas
2015-02-04 23:08           ` Wei Yang
2015-01-15  2:28       ` [PATCH V11 13/17] powerpc/powernv: Implement pcibios_iov_resource_alignment() on powernv Wei Yang
2015-02-04 21:26         ` Bjorn Helgaas
2015-02-04 22:45           ` Wei Yang [this message]
2015-01-15  2:28       ` [PATCH V11 14/17] powerpc/powernv: Shift VF resource with an offset Wei Yang
2015-01-30 23:08         ` Bjorn Helgaas
2015-02-03  1:30           ` Wei Yang
2015-02-03  7:01           ` [PATCH] powerpc/powernv: make sure the IOV BAR will not exceed limit after shifting Wei Yang
2015-02-04  0:19             ` Bjorn Helgaas
2015-02-04  3:34               ` Wei Yang
2015-02-04 14:19                 ` Bjorn Helgaas
2015-02-04 15:20                   ` Wei Yang
2015-02-04 16:08                   ` [PATCH] pci/iov: fix memory leak introduced in "PCI: Store individual VF BAR size in struct pci_sriov" Wei Yang
2015-02-04 16:28                     ` Bjorn Helgaas
2015-02-04 20:53                 ` [PATCH] powerpc/powernv: make sure the IOV BAR will not exceed limit after shifting Bjorn Helgaas
2015-02-05  3:01                   ` Wei Yang
2015-01-15  2:28       ` [PATCH V11 15/17] powerpc/powernv: Allocate VF PE Wei Yang
2015-01-15  2:28       ` [PATCH V11 16/17] powerpc/powernv: Reserve additional space for IOV BAR, with m64_per_iov supported Wei Yang
2015-02-04 22:05         ` Bjorn Helgaas
2015-02-05  0:07           ` Wei Yang
2015-01-15  2:28       ` [PATCH V11 17/17] powerpc/powernv: Group VF PE when IOV BAR is big on PHB3 Wei Yang
2015-02-04 23:44       ` [PATCH V11 00/17] Enable SRIOV on Power8 Bjorn Helgaas
2015-02-05  0:13         ` Wei Yang
2015-02-05  6:34         ` [PATCH 0/3] Code adjustment on pci/virtualization Wei Yang
2015-02-05  6:34           ` [PATCH 1/3] fix on Store individual VF BAR size in struct pci_sriov Wei Yang
2015-02-05  6:34           ` [PATCH 2/3] fix Reserve additional space for IOV BAR, with m64_per_iov supported Wei Yang
2015-02-05  6:34           ` [PATCH 3/3] remove the unused end in pnv_pci_vf_resource_shift() Wei Yang
2015-02-10  0:25         ` [PATCH V11 00/17] Enable SRIOV on Power8 Benjamin Herrenschmidt

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=20150204224540.GA18037@richard \
    --to=weiyang@linux.vnet.ibm.com \
    --cc=benh@au1.ibm.com \
    --cc=bhelgaas@google.com \
    --cc=gwshan@linux.vnet.ibm.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    /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).