[03/11] powerpc/powernv/ioda: set up PE on opencapi device when enabling
diff mbox series

Message ID 20190909154600.19917-4-fbarrat@linux.ibm.com
State New
Headers show
Series
  • opencapi: enable card reset and link retraining
Related show

Checks

Context Check Description
snowpatch_ozlabs/checkpatch success total: 0 errors, 0 warnings, 0 checks, 55 lines checked
snowpatch_ozlabs/apply_patch success Successfully applied on branch next (c317052c95bef1f977b023158e5aa929215f443d)

Commit Message

Frederic Barrat Sept. 9, 2019, 3:45 p.m. UTC
The PE for an opencapi device was set as part of a late PHB fixup
operation, when creating the PHB. To use the PCI hotplug framework,
this is not going to work, as the PHB stays the same, it's only the
devices underneath which are updated. For regular PCI devices, it is
done as part of the reconfiguration of the bridge, but for opencapi
PHBs, we don't have an intermediate bridge. So let's define the PE
when the device is enabled. PEs are meaningless for opencapi, the NPU
doesn't define them and opal is not doing anything with them.

Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
---
 arch/powerpc/platforms/powernv/pci-ioda.c | 31 +++++++++++++++++------
 1 file changed, 23 insertions(+), 8 deletions(-)

Comments

Alastair D'Silva Sept. 10, 2019, 12:38 a.m. UTC | #1
On Mon, 2019-09-09 at 17:45 +0200, Frederic Barrat wrote:
> The PE for an opencapi device was set as part of a late PHB fixup
> operation, when creating the PHB. To use the PCI hotplug framework,
> this is not going to work, as the PHB stays the same, it's only the
> devices underneath which are updated. For regular PCI devices, it is
> done as part of the reconfiguration of the bridge, but for opencapi
> PHBs, we don't have an intermediate bridge. So let's define the PE
> when the device is enabled. PEs are meaningless for opencapi, the NPU
> doesn't define them and opal is not doing anything with them.
> 
> Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
> ---
>  arch/powerpc/platforms/powernv/pci-ioda.c | 31 +++++++++++++++++--
> ----
>  1 file changed, 23 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c
> b/arch/powerpc/platforms/powernv/pci-ioda.c
> index 3dbbf5365c1c..06ce7ddaa0cf 100644
> --- a/arch/powerpc/platforms/powernv/pci-ioda.c
> +++ b/arch/powerpc/platforms/powernv/pci-ioda.c
> @@ -1260,8 +1260,6 @@ static void pnv_pci_ioda_setup_PEs(void)
>  {
>  	struct pci_controller *hose;
>  	struct pnv_phb *phb;
> -	struct pci_bus *bus;
> -	struct pci_dev *pdev;
>  	struct pnv_ioda_pe *pe;
>  
>  	list_for_each_entry(hose, &hose_list, list_node) {
> @@ -1273,11 +1271,6 @@ static void pnv_pci_ioda_setup_PEs(void)
>  			if (phb->model == PNV_PHB_MODEL_NPU2)
>  				WARN_ON_ONCE(pnv_npu2_init(hose));
>  		}
> -		if (phb->type == PNV_PHB_NPU_OCAPI) {
> -			bus = hose->bus;
> -			list_for_each_entry(pdev, &bus->devices,
> bus_list)
> -				pnv_ioda_setup_dev_PE(pdev);
> -		}
>  	}
>  	list_for_each_entry(hose, &hose_list, list_node) {
>  		phb = hose->private_data;
> @@ -3385,6 +3378,28 @@ static bool pnv_pci_enable_device_hook(struct
> pci_dev *dev)
>  	return true;
>  }
>  
> +static bool pnv_ocapi_enable_device_hook(struct pci_dev *dev)
> +{
> +	struct pci_controller *hose = pci_bus_to_host(dev->bus);
> +	struct pnv_phb *phb = hose->private_data;
> +	struct pci_dn *pdn;
> +	struct pnv_ioda_pe *pe;
> +
> +	if (!phb->initialized)
> +		return true;
> +
> +	pdn = pci_get_pdn(dev);
> +	if (!pdn)
> +		return false;
> +
> +	if (pdn->pe_number == IODA_INVALID_PE) {
> +		pe = pnv_ioda_setup_dev_PE(dev);
> +		if (!pe)
> +			return false;
> +	}
> +	return true;
> +}
> +
>  static long pnv_pci_ioda1_unset_window(struct iommu_table_group
> *table_group,
>  				       int num)
>  {
> @@ -3625,7 +3640,7 @@ static const struct pci_controller_ops
> pnv_npu_ioda_controller_ops = {
>  };
>  
>  static const struct pci_controller_ops
> pnv_npu_ocapi_ioda_controller_ops = {
> -	.enable_device_hook	= pnv_pci_enable_device_hook,
> +	.enable_device_hook	= pnv_ocapi_enable_device_hook,
>  	.window_alignment	= pnv_pci_window_alignment,
>  	.reset_secondary_bus	= pnv_pci_reset_secondary_bus,
>  	.shutdown		= pnv_pci_ioda_shutdown,

Reviewed-by: Alastair D'Silva <alastair@d-silva.org>

Patch
diff mbox series

diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 3dbbf5365c1c..06ce7ddaa0cf 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -1260,8 +1260,6 @@  static void pnv_pci_ioda_setup_PEs(void)
 {
 	struct pci_controller *hose;
 	struct pnv_phb *phb;
-	struct pci_bus *bus;
-	struct pci_dev *pdev;
 	struct pnv_ioda_pe *pe;
 
 	list_for_each_entry(hose, &hose_list, list_node) {
@@ -1273,11 +1271,6 @@  static void pnv_pci_ioda_setup_PEs(void)
 			if (phb->model == PNV_PHB_MODEL_NPU2)
 				WARN_ON_ONCE(pnv_npu2_init(hose));
 		}
-		if (phb->type == PNV_PHB_NPU_OCAPI) {
-			bus = hose->bus;
-			list_for_each_entry(pdev, &bus->devices, bus_list)
-				pnv_ioda_setup_dev_PE(pdev);
-		}
 	}
 	list_for_each_entry(hose, &hose_list, list_node) {
 		phb = hose->private_data;
@@ -3385,6 +3378,28 @@  static bool pnv_pci_enable_device_hook(struct pci_dev *dev)
 	return true;
 }
 
+static bool pnv_ocapi_enable_device_hook(struct pci_dev *dev)
+{
+	struct pci_controller *hose = pci_bus_to_host(dev->bus);
+	struct pnv_phb *phb = hose->private_data;
+	struct pci_dn *pdn;
+	struct pnv_ioda_pe *pe;
+
+	if (!phb->initialized)
+		return true;
+
+	pdn = pci_get_pdn(dev);
+	if (!pdn)
+		return false;
+
+	if (pdn->pe_number == IODA_INVALID_PE) {
+		pe = pnv_ioda_setup_dev_PE(dev);
+		if (!pe)
+			return false;
+	}
+	return true;
+}
+
 static long pnv_pci_ioda1_unset_window(struct iommu_table_group *table_group,
 				       int num)
 {
@@ -3625,7 +3640,7 @@  static const struct pci_controller_ops pnv_npu_ioda_controller_ops = {
 };
 
 static const struct pci_controller_ops pnv_npu_ocapi_ioda_controller_ops = {
-	.enable_device_hook	= pnv_pci_enable_device_hook,
+	.enable_device_hook	= pnv_ocapi_enable_device_hook,
 	.window_alignment	= pnv_pci_window_alignment,
 	.reset_secondary_bus	= pnv_pci_reset_secondary_bus,
 	.shutdown		= pnv_pci_ioda_shutdown,