Skip to contentSkip to conversation

SR-IOV Enablement on PowerVM

PATCH New Bryant G. Ly 5 participants 15 messages Dec 18, 2017 – Dec 29, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover SR-IOV Enablement on PowerVM

This patch series will enable SR-IOV on PowerVM. A specific set of lids for PFW/PHYP is required. They are planned to release with 920 at the moment.

For IBM internal testers let me know of a system you want to test on and we can put on the lids required or we can provide a system to run the tests.

This patch depends on the three patches:
988fc3ba5653278a8c14d6ccf687371775930d2b
dae7253f9f78a731755ca20c66b2d2c40b86baea
608c0d8804ef3ca4cda8ec6ad914e47deb283d7b

v1 - Initial Patch
v2 - Addressed Alexey and Russell's comments

Bryant G. Ly (7):
platform/pseries: Update VF config space after EEH powerpc/kernel: Add uevents in EEH error/resume platforms/pseries: Set eeh_pe of EEH_PE_VF type powerpc/kernel Add EEH operations to notify resume powerpc/kernel: Add EEH notify resume sysfs pseries/pci: Associate PEs to VFs in configure SR-IOV pseries/setup: Add Initialization of VF Bars

 arch/powerpc/include/asm/eeh.h               |   1 +
 arch/powerpc/include/asm/pci-bridge.h        |   5 +-
 arch/powerpc/include/asm/pci.h               |   2 +
 arch/powerpc/kernel/eeh_driver.c             |   9 +-
 arch/powerpc/kernel/eeh_sysfs.c              |  46 ++++++-
 arch/powerpc/kernel/pci_of_scan.c            |   2 +-
 arch/powerpc/platforms/powernv/eeh-powernv.c |   3 +-
 arch/powerpc/platforms/pseries/eeh_pseries.c | 192 ++++++++++++++++++++++++++-
 arch/powerpc/platforms/pseries/pci.c         | 156 +++++++++++++++++++++-
 arch/powerpc/platforms/pseries/setup.c       | 183 +++++++++++++++++++++++++
 10 files changed, 589 insertions(+), 10 deletions(-)
Signature · 1 line
2.14.3 (Apple Git-98)
#1 lore raw

PATCH v2 1/7 platform/pseries: Update VF config space after EEH

Add EEH platform operations for pseries to update VF config space. With this change after EEH, the VF will have updated config space for pseries platform.

---
 arch/powerpc/include/asm/eeh.h               |  1 +
 arch/powerpc/kernel/eeh.c                    | 59 +++++++++++++++++++++++++
 arch/powerpc/platforms/powernv/eeh-powernv.c | 65 ++--------------------------
 arch/powerpc/platforms/pseries/eeh_pseries.c | 26 ++++++++++-
 4 files changed, 88 insertions(+), 63 deletions(-)
arch/powerpc/include/asm/eeh.h +1 -0
index 5161c37dd039..82829c65f31a 100644
@@ -297,6 +297,7 @@ int eeh_pe_reset(struct eeh_pe *pe, int option);
 int eeh_pe_configure(struct eeh_pe *pe);
 int eeh_pe_inject_err(struct eeh_pe *pe, int type, int func,
 		      unsigned long addr, unsigned long mask);
+int eeh_restore_vf_config(struct pci_dn *pdn);
 
 /**
  * EEH_POSSIBLE_ERROR() -- test for possible MMIO failure.
arch/powerpc/kernel/eeh.c +59 -0

65 lines not on this page · raw message

arch/powerpc/platforms/powernv/eeh-powernv.c +3 -62

87 lines not on this page · raw message

arch/powerpc/platforms/pseries/eeh_pseries.c +25 -1
index 2295f117e2d3..a671ef4f57f5 100644
@@ -708,6 +708,30 @@ static int pseries_eeh_write_config(struct pci_dn *pdn, int where, int size, u32
 	return rtas_write_config(pdn, where, size, val);
 }
 
+static int pseries_eeh_restore_config(struct pci_dn *pdn)
+{
+	struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
+	s64 ret = 0;
+
+	if (!edev)
+		return -EEXIST;
+
+	/*
+	 * FIXME: The MPS, error routing rules, timeout setting are worthy
+	 * to be exported by firmware in extendible way.
+	 */
+	if (edev->physfn)
+		ret = eeh_restore_vf_config(pdn);
+
+	if (ret) {
+		pr_warn("%s: Can't reinit PCI dev 0x%x (%lld)\n",
+			__func__, edev->pe_config_addr, ret);
+		return -EIO;
+	}
+
+	return ret;
+}
+
 static struct eeh_ops pseries_eeh_ops = {
 	.name			= "pseries",
 	.init			= pseries_eeh_init,
@@ -723,7 +747,7 @@ static struct eeh_ops pseries_eeh_ops = {
 	.read_config		= pseries_eeh_read_config,
 	.write_config		= pseries_eeh_write_config,
 	.next_error		= NULL,
-	.restore_config		= NULL
+	.restore_config		= pseries_eeh_restore_config
 };
 
 /**
Signature · 1 line
2.14.3 (Apple Git-98)
#2 lore raw

PATCH v2 2/7 powerpc/kernel: Add uevents in EEH error/resume

In reply to Bryant G. Ly

Devices can go offline when EEH is reported. This patch adds a change to the kernel object and lets udev know of error. When device resumes a change is also set reporting device as online. Therefore, EEH events are better propagated to user space for devices in powerpc arch.

---
 arch/powerpc/kernel/eeh_driver.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/powerpc/kernel/eeh_driver.c +6 -0
index 3c0fa99c5533..9d4e8177c2e0 100644
@@ -204,6 +204,7 @@ static void *eeh_report_error(void *data, void *userdata)
 	struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
 	enum pci_ers_result rc, *res = userdata;
 	struct pci_driver *driver;
+	char *envp[] = {"EVENT=EEH_ERROR", "ONLINE=0", NULL};
 
 	if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
 		return NULL;
@@ -228,6 +229,7 @@ static void *eeh_report_error(void *data, void *userdata)
 
 	edev->in_error = true;
 	eeh_pcid_put(dev);
+	kobject_uevent_env(&dev->dev.kobj, KOBJ_CHANGE, envp);
 	return NULL;
 }
 
@@ -358,6 +360,7 @@ static void *eeh_report_resume(void *data, void *userdata)
 	struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
 	bool was_in_error;
 	struct pci_driver *driver;
+	char *envp[] = {"EVENT=EEH_RESUME", "ONLINE=1", NULL};
 
 	if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
 		return NULL;
@@ -381,6 +384,7 @@ static void *eeh_report_resume(void *data, void *userdata)
 	driver->err_handler->resume(dev);
 
 	eeh_pcid_put(dev);
+	kobject_uevent_env(&dev->dev.kobj, KOBJ_CHANGE, envp);
 	return NULL;
 }
 
@@ -397,6 +401,7 @@ static void *eeh_report_failure(void *data, void *userdata)
 	struct eeh_dev *edev = (struct eeh_dev *)data;
 	struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
 	struct pci_driver *driver;
+	char * envp[] = {"EVENT=EEH_PERMANENT_FAILURE", "ONLINE=0", NULL};
 
 	if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
 		return NULL;
@@ -415,6 +420,7 @@ static void *eeh_report_failure(void *data, void *userdata)
 
 	driver->err_handler->error_detected(dev, pci_channel_io_perm_failure);
 
+	kobject_uevent_env(&dev->dev.kobj, KOBJ_CHANGE, envp);
 	eeh_pcid_put(dev);
 	return NULL;
 }
Signature · 1 line
2.14.3 (Apple Git-98)
#3 lore raw

Re: [PATCH v2 2/7] powerpc/kernel: Add uevents in EEH error/resume

[+cc Keith, Gabriele, Dongdong]

Quoted 5 lines · Bryant G. Ly

Devices can go offline when EEH is reported. This patch adds a change to the kernel object and lets udev know of error. When device resumes a change is also set reporting device as online. Therefore, EEH events are better propagated to user space for devices in powerpc arch.

I'm on vacation and can't review this in detail, but I wonder if you can compare this with the uevents we emit for DPC, AER, and hotplug events (if any). I hope we don't end up with userspace having to be aware of the differences between EEH, DPC, AER, etc.

Quoted 1 line

From a very quick look, I only see a few uevents even mentioned in

drivers/pci: KOBJ_ADD in __pci_hp_register() and KOBJ_CHANGE in the SR-IOV code. I'm worried that we're missing some important uevents in the PCI core. That's not an argument against what you're doing here; it just would be nice to fill in any missing pieces in the core also, and hopefully make them consistent with these EEH events.

Quoted 61 lines
---
 arch/powerpc/kernel/eeh_driver.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/powerpc/kernel/eeh_driver.c +6 -0
index 3c0fa99c5533..9d4e8177c2e0 100644
@@ -204,6 +204,7 @@ static void *eeh_report_error(void *data, void *userdata)
 	struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
 	enum pci_ers_result rc, *res = userdata;
 	struct pci_driver *driver;
+	char *envp[] = {"EVENT=EEH_ERROR", "ONLINE=0", NULL};
 
 	if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
 		return NULL;
@@ -228,6 +229,7 @@ static void *eeh_report_error(void *data, void *userdata)
 
 	edev->in_error = true;
 	eeh_pcid_put(dev);
+	kobject_uevent_env(&dev->dev.kobj, KOBJ_CHANGE, envp);
 	return NULL;
 }
 
@@ -358,6 +360,7 @@ static void *eeh_report_resume(void *data, void *userdata)
 	struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
 	bool was_in_error;
 	struct pci_driver *driver;
+	char *envp[] = {"EVENT=EEH_RESUME", "ONLINE=1", NULL};
 
 	if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
 		return NULL;
@@ -381,6 +384,7 @@ static void *eeh_report_resume(void *data, void *userdata)
 	driver->err_handler->resume(dev);
 
 	eeh_pcid_put(dev);
+	kobject_uevent_env(&dev->dev.kobj, KOBJ_CHANGE, envp);
 	return NULL;
 }
 
@@ -397,6 +401,7 @@ static void *eeh_report_failure(void *data, void *userdata)
 	struct eeh_dev *edev = (struct eeh_dev *)data;
 	struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
 	struct pci_driver *driver;
+	char * envp[] = {"EVENT=EEH_PERMANENT_FAILURE", "ONLINE=0", NULL};
 
 	if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
 		return NULL;
@@ -415,6 +420,7 @@ static void *eeh_report_failure(void *data, void *userdata)
 
 	driver->err_handler->error_detected(dev, pci_channel_io_perm_failure);
 
+	kobject_uevent_env(&dev->dev.kobj, KOBJ_CHANGE, envp);
 	eeh_pcid_put(dev);
 	return NULL;
 }
Signature · 1 line
2.14.3 (Apple Git-98)
#4 lore raw

Re: [PATCH v2 2/7] powerpc/kernel: Add uevents in EEH error/resume

Quoted 14 lines · Bjorn Helgaas

[+cc Keith, Gabriele, Dongdong]

Quoted 5 lines · Bryant G. Ly

Devices can go offline when EEH is reported. This patch adds a change to the kernel object and lets udev know of error. When device resumes a change is also set reporting device as online. Therefore, EEH events are better propagated to user space for devices in powerpc arch.

I'm on vacation and can't review this in detail, but I wonder if you can compare this with the uevents we emit for DPC, AER, and hotplug events (if any). I hope we don't end up with userspace having to be aware of the differences between EEH, DPC, AER, etc.

Quoted 7 lines

From a very quick look, I only see a few uevents even mentioned in drivers/pci: KOBJ_ADD in __pci_hp_register() and KOBJ_CHANGE in the SR-IOV code. I'm worried that we're missing some important uevents in
the PCI core. That's not an argument against what you're doing here; it just would be nice to fill in any missing pieces in the core also, and hopefully make them consistent with these EEH events.

I don't think this needs to be particularly complex, could we get away with events for when devices do the following?

- begin recovery
- successfully recover
- fail recovery

It might be worthwhile sorting out some consistent, non-EEH-specific naming, and then other device error recovery systems can do the same later.

- Russell

Quoted 3 lines
Quoted 3 lines
#5 lore raw

Re: [PATCH v2 2/7] powerpc/kernel: Add uevents in EEH error/resume

Quoted 14 lines · Russell Currey
Quoted 13 lines · Bjorn Helgaas

[+cc Keith, Gabriele, Dongdong]

Quoted 5 lines · Bryant G. Ly

Devices can go offline when EEH is reported. This patch adds a change to the kernel object and lets udev know of error. When device resumes a change is also set reporting device as online. Therefore, EEH events are better propagated to user space for devices in powerpc arch.

I'm on vacation and can't review this in detail, but I wonder if you can compare this with the uevents we emit for DPC, AER, and hotplug events (if any). I hope we don't end up with userspace having to be aware of the differences between EEH, DPC, AER, etc.

Quoted 5 lines
Quoted 5 lines

From a very quick look, I only see a few uevents even mentioned in drivers/pci: KOBJ_ADD in __pci_hp_register() and KOBJ_CHANGE in the SR-IOV code. I'm worried that we're missing some important uevents in
the PCI core.

The only place where I see the KOBJ_REMOVE being used is when the device is removed in pci_destroy_dev -> device_del whic will be called implicitly in permanent failure path of EEH code

Quoted 9 lines
Quoted 3 lines

That's not an argument against what you're doing here;
it just would be nice to fill in any missing pieces in the core also, and hopefully make them consistent with these EEH events.

I don't think this needs to be particularly complex, could we get away with events for when devices do the following?

- begin recovery
- successfully recover
- fail recovery

If there are no objections in the on going review of this patch I can change them to these names:

- BEGIN_RECOVERY
- SUCCESSFUL_RECOVERY
- FAILED_RECOVERY

Quoted 5 lines

It might be worthwhile sorting out some consistent, non-EEH-specific naming, and then other device error recovery systems can do the same later.

Do you have a more consistent naming in mind for these events?

- Juan

#6 lore raw

Re: [PATCH v2 2/7] powerpc/kernel: Add uevents in EEH error/resume

In reply to Bjorn Helgaas
Quoted 14 lines · Bjorn Helgaas

[+cc Keith, Gabriele, Dongdong]

Quoted 5 lines · Bryant G. Ly

Devices can go offline when EEH is reported. This patch adds a change to the kernel object and lets udev know of error. When device resumes a change is also set reporting device as online. Therefore, EEH events are better propagated to user space for devices in powerpc arch.

I'm on vacation and can't review this in detail, but I wonder if you can compare this with the uevents we emit for DPC, AER, and hotplug events (if any). I hope we don't end up with userspace having to be aware of the differences between EEH, DPC, AER, etc.

Quoted 7 lines
Quoted 1 line

From a very quick look, I only see a few uevents even mentioned in

drivers/pci: KOBJ_ADD in __pci_hp_register() and KOBJ_CHANGE in the SR-IOV code. I'm worried that we're missing some important uevents in the PCI core. That's not an argument against what you're doing here; it just would be nice to fill in any missing pieces in the core also, and hopefully make them consistent with these EEH events.

We also need to be careful about what specific EEH activity we are talking about, and if we bring into the picture things like DPDK, it gets even more murky...

The basic way EEH is supposed to work for recovery (minus all sort of implementation nasties which hopefully Russell and Sam are trying to cleanup and fix) is that either:

- The driver of the device has recovery callbacks, in which
case the driver participates in the recovery process, the device doesn't "go away" (though it shouldn't be accessed during that process by other entities, userspace originated config space could be a problem and needs to be blocked...). The recovery typically involves a reset of the device but in sync with the driver.

- The driver doesn't have the callbacks. In this case, we
simulate an unplug, reset the device, and replug.

So it makes sense for the second case to emit the same uevents as a normal PCI(e) hotplug.

For the former case I'm less sure.... Do we really need userspace to be notified ? If yes, what for precisely ?

Cheers,
Ben.

#7 lore raw

Re: [PATCH v2 2/7] powerpc/kernel: Add uevents in EEH error/resume

Quoted 35 lines · Benjamin Herrenschmidt
Quoted 13 lines · Bjorn Helgaas

[+cc Keith, Gabriele, Dongdong]

Quoted 5 lines · Bryant G. Ly

Devices can go offline when EEH is reported. This patch adds a change to the kernel object and lets udev know of error. When device resumes a change is also set reporting device as online. Therefore, EEH events are better propagated to user space for devices in powerpc arch.

I'm on vacation and can't review this in detail, but I wonder if you can compare this with the uevents we emit for DPC, AER, and hotplug events (if any). I hope we don't end up with userspace having to be aware of the differences between EEH, DPC, AER, etc.

Quoted 6 lines
Quoted 1 line

From a very quick look, I only see a few uevents even mentioned in

drivers/pci: KOBJ_ADD in __pci_hp_register() and KOBJ_CHANGE in the SR-IOV code. I'm worried that we're missing some important uevents in the PCI core. That's not an argument against what you're doing here; it just would be nice to fill in any missing pieces in the core also, and hopefully make them consistent with these EEH events.

We also need to be careful about what specific EEH activity we are talking about, and if we bring into the picture things like DPDK, it gets even more murky...

The basic way EEH is supposed to work for recovery (minus all sort of implementation nasties which hopefully Russell and Sam are trying to cleanup and fix) is that either:

- The driver of the device has recovery callbacks, in which
case the driver participates in the recovery process, the device doesn't "go away" (though it shouldn't be accessed during that process by other entities, userspace originated config space could be a problem and needs to be blocked...). The recovery typically involves a reset of the device but in sync with the driver.

Quoted 8 lines

- The driver doesn't have the callbacks. In this case, we
simulate an unplug, reset the device, and replug.

So it makes sense for the second case to emit the same uevents as a normal PCI(e) hotplug.

For the former case I'm less sure.... Do we really need userspace to be notified ? If yes, what for precisely ?

In pSeries SR-IOV environment the management console might need to apply certain configuration changes to the PF driver after it has been recovered and before the VF drivers are allowed to resume their recovery path. I could not think of another way to notify user space of these events. I made this assumption because I saw there were no uevents added when the device goes offline and come back online in EEH code. It was my intention to make the event as generic as possible in EEH component, therefore, making this change independent of pSeries SR-IOV.

- Juan

#8 lore raw

Re: [PATCH v2 2/7] powerpc/kernel: Add uevents in EEH error/resume

Quoted 46 lines · Juan Alvarez
Quoted 35 lines · Benjamin Herrenschmidt
Quoted 13 lines · Bjorn Helgaas

[+cc Keith, Gabriele, Dongdong]

Quoted 5 lines · Bryant G. Ly

Devices can go offline when EEH is reported. This patch adds a change to the kernel object and lets udev know of error. When device resumes a change is also set reporting device as online. Therefore, EEH events are better propagated to user space for devices in powerpc arch.

I'm on vacation and can't review this in detail, but I wonder if you can compare this with the uevents we emit for DPC, AER, and hotplug events (if any). I hope we don't end up with userspace having to be aware of the differences between EEH, DPC, AER, etc.

Quoted 6 lines
Quoted 1 line

From a very quick look, I only see a few uevents even mentioned in

drivers/pci: KOBJ_ADD in __pci_hp_register() and KOBJ_CHANGE in the SR-IOV code. I'm worried that we're missing some important uevents in the PCI core. That's not an argument against what you're doing here; it just would be nice to fill in any missing pieces in the core also, and hopefully make them consistent with these EEH events.

We also need to be careful about what specific EEH activity we are talking about, and if we bring into the picture things like DPDK, it gets even more murky...

The basic way EEH is supposed to work for recovery (minus all sort of implementation nasties which hopefully Russell and Sam are trying to cleanup and fix) is that either:

- The driver of the device has recovery callbacks, in which
case the driver participates in the recovery process, the device doesn't "go away" (though it shouldn't be accessed during that process by other entities, userspace originated config space could be a problem and needs to be blocked...). The recovery typically involves a reset of the device but in sync with the driver.

Quoted 8 lines

- The driver doesn't have the callbacks. In this case, we
simulate an unplug, reset the device, and replug.

So it makes sense for the second case to emit the same uevents as a normal PCI(e) hotplug.

For the former case I'm less sure.... Do we really need userspace to be notified ? If yes, what for precisely ?

Quoted 8 lines

In pSeries SR-IOV environment the management console might need to apply certain configuration changes to the PF driver after it has been recovered and before the VF drivers are allowed to resume their recovery path. I could not think of another way to notify user space of these events. I made this assumption because I saw there were no uevents added when the device goes offline and come back online in EEH code. It was my intention to make the event as generic as possible in EEH component, therefore, making this change independent of pSeries SR-IOV.

I don't know what your plan for this is, but we do have two different paths that use the struct pci_error_handlers hooks that drivers may supply. There's this AER path that may be used on all arches:

aer_isr
get_e_source # remove from rpc->e_sources[] queue
aer_isr_one_error
aer_process_err_devices
handle_error_source # or aer_recover_work_func
do_recovery # for uncorrectable (fatal/nonfatal) only
broadcast_error_message(dev, ..., report_error_detected)
pci_walk_bus(..., report_error_detected)
report_error_detected
dev->driver->err_handler->error_detected

And there's this powerpc path where you're adding a uevent:

eeh_event_handler
eeh_handle_event
eeh_handle_normal_event
eeh_pe_dev_traverse(pe, eeh_report_error, &result)
eeh_report_error
driver->err_handler->error_detected(dev, pci_channel_io_frozen)
+ kobject_uevent_env(&dev->dev.kobj, KOBJ_CHANGE, envp);

Both paths end up calling the pci_error_handlers.error_detected() hook.

Drivers are not supposed to care what arch they're running on. If the driver supplies an .error_detected() entry point, it's up to the PCI core and powerpc code to use it consistently across arches. That means the same uevents (if any) should be emitted from both paths.

The best way would be to unify the call of .error_detected() so the AER path and the powerpc path do it via the same function. The AER report_error_detected() and the powerpc eeh_report_error() do look fairly similar, so this seems possible in principle, but I'm not holding my breath.

Bjorn

#9 lore raw

Re: [PATCH v2 2/7] powerpc/kernel: Add uevents in EEH error/resume

Quoted 8 lines · Bjorn Helgaas

Both paths end up calling the pci_error_handlers.error_detected() hook.

Drivers are not supposed to care what arch they're running on. If the driver supplies an .error_detected() entry point, it's up to the PCI core and powerpc code to use it consistently across arches. That means the same uevents (if any) should be emitted from both paths.

Quoted 5 lines

The best way would be to unify the call of .error_detected() so the AER path and the powerpc path do it via the same function. The AER report_error_detected() and the powerpc eeh_report_error() do look fairly similar, so this seems possible in principle, but I'm not holding my breath.

Factoring these callers into a common function that can then do the uevent for errors makes a lot of sense.

The "resume" path might be trickier, but even then, rather than calling directly the driver op, it would be easy to have a little wrapper that does it, which can then also do the uevent.

Ben.

#10 lore raw

PATCH v2 3/7 platforms/pseries: Set eeh_pe of EEH_PE_VF type

In reply to Bryant G. Ly

To correctly use EEH code one has to make sure that the EEH_PE_VF is set for dynamic created VFs. Therefore this patch allocates an eeh_pe of eeh type EEH_PE_VF and associates PE with parent.

---
 arch/powerpc/include/asm/pci-bridge.h        |  5 ++++-
 arch/powerpc/platforms/pseries/eeh_pseries.c | 13 ++++++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/pci-bridge.h +4 -1
index 9f66ddebb799..16d70740a76f 100644
@@ -211,7 +211,10 @@ struct pci_dn {
 	unsigned int *pe_num_map;	/* PE# for the first VF PE or array */
 	bool    m64_single_mode;	/* Use M64 BAR in Single Mode */
 #define IODA_INVALID_M64        (-1)
-	int     (*m64_map)[PCI_SRIOV_NUM_BARS];
+	union {
+		int     (*m64_map)[PCI_SRIOV_NUM_BARS]; /*Only used in powernv */
+		int     last_allow_rc;	/* Only used in pSeries */
+	};
 #endif /* CONFIG_PCI_IOV */
 	int	mps;			/* Maximum Payload Size */
 	struct list_head child_list;
arch/powerpc/platforms/pseries/eeh_pseries.c +12 -1
index a671ef4f57f5..c4bc5dd0c6ec 100644
@@ -58,6 +58,8 @@ static int ibm_configure_pe;
 void pseries_pcibios_bus_add_device(struct pci_dev *pdev)
 {
 	struct pci_dn *pdn = pci_get_pdn(pdev);
+	struct pci_dn *physfn_pdn;
+	struct eeh_dev *edev;
 
 	if (!pdev->is_virtfn)
 		return;
@@ -65,6 +67,14 @@ void pseries_pcibios_bus_add_device(struct pci_dev *pdev)
 	pdn->device_id  =  pdev->device;
 	pdn->vendor_id  =  pdev->vendor;
 	pdn->class_code =  pdev->class;
+	/* Last allow unfreeze return code used for retrieval
+	 * by user space in eeh-sysfs to show the last command
+	 * completion from platform
+	 */
+	pdn->last_allow_rc =  0;
+	physfn_pdn      =  pci_get_pdn(pdev->physfn);
+	pdn->pe_number  =  physfn_pdn->pe_num_map[pdn->vf_index];
+	edev = pdn_to_eeh_dev(pdn);
 
 	/*
 	 * The following operations will fail if VF's sysfs files
@@ -72,8 +82,9 @@ void pseries_pcibios_bus_add_device(struct pci_dev *pdev)
 	 */
 	eeh_add_device_early(pdn);
 	eeh_add_device_late(pdev);
+	edev->pe_config_addr =  (pdn->busno << 16) | (pdn->devfn << 8);
+	eeh_add_to_parent_pe(edev);
 	eeh_sysfs_add_device(pdev);
-
 }
 
 /*
Signature · 1 line
2.14.3 (Apple Git-98)
#11 lore raw

PATCH v2 4/7 powerpc/kernel Add EEH operations to notify resume

In reply to Bryant G. Ly

When pseries SR-IOV is enabled and after a PF driver has resumed from EEH, platform has to be notified of the event so the child VFs can be allowed to resume their normal recovery path.

This patch makes the EEH operation allow unfreeze platform dependent code and adds the call to pseries EEH code.

---
 arch/powerpc/include/asm/eeh.h               |  1 +
 arch/powerpc/kernel/eeh_driver.c             |  3 +
 arch/powerpc/platforms/powernv/eeh-powernv.c |  3 +-
 arch/powerpc/platforms/pseries/eeh_pseries.c | 90 +++++++++++++++++++++++++++-
 4 files changed, 95 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/eeh.h +1 -0
index 82829c65f31a..fd37cc101f4f 100644
@@ -214,6 +214,7 @@ struct eeh_ops {
 	int (*write_config)(struct pci_dn *pdn, int where, int size, u32 val);
 	int (*next_error)(struct eeh_pe **pe);
 	int (*restore_config)(struct pci_dn *pdn);
+	int (*notify_resume)(struct pci_dn *pdn);
 };
 
 extern int eeh_subsystem_flags;
arch/powerpc/kernel/eeh_driver.c +3 -0
index 9d4e8177c2e0..ed710076b042 100644
@@ -385,6 +385,9 @@ static void *eeh_report_resume(void *data, void *userdata)
 
 	eeh_pcid_put(dev);
 	kobject_uevent_env(&dev->dev.kobj, KOBJ_CHANGE, envp);
+#ifdef CONFIG_PCI_IOV
+	eeh_ops->notify_resume(eeh_dev_to_pdn(edev));
+#endif
 	return NULL;
 }
 
arch/powerpc/platforms/powernv/eeh-powernv.c +2 -1
index 0665b6d03cb3..33c86c1a1720 100644
@@ -1704,7 +1704,8 @@ static struct eeh_ops pnv_eeh_ops = {
 	.read_config            = pnv_eeh_read_config,
 	.write_config           = pnv_eeh_write_config,
 	.next_error		= pnv_eeh_next_error,
-	.restore_config		= pnv_eeh_restore_config
+	.restore_config		= pnv_eeh_restore_config,
+	.notify_resume		= NULL
 };
 
 #ifdef CONFIG_PCI_IOV
arch/powerpc/platforms/pseries/eeh_pseries.c +89 -1

102 lines not on this page · raw message

Signature · 1 line
2.14.3 (Apple Git-98)
#12 lore raw

PATCH v2 5/7 powerpc/kernel: Add EEH notify resume sysfs

In reply to Bryant G. Ly

Introduce a method for notify resume to be
called from sysfs. In this patch one can
now call notify resume from sysfs when
is supported by platform.

---
 arch/powerpc/kernel/eeh_sysfs.c | 46 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)
arch/powerpc/kernel/eeh_sysfs.c +45 -1
index 797549289798..344e7607f2e0 100644
@@ -90,6 +90,38 @@ static ssize_t eeh_pe_state_store(struct device *dev,
 
 static DEVICE_ATTR_RW(eeh_pe_state);
 
+#ifdef CONFIG_PCI_IOV
+static ssize_t eeh_notify_resume_show(struct device *dev,
+				      struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct eeh_dev *edev = pci_dev_to_eeh_dev(pdev);
+	struct pci_dn *pdn = pci_get_pdn(pdev);
+
+	if (!edev || !edev->pe)
+		return -ENODEV;
+
+	pdn = pci_get_pdn(pdev);
+	return sprintf(buf, "%d\n", pdn->last_allow_rc);
+}
+
+static ssize_t eeh_notify_resume_store(struct device *dev,
+				       struct device_attribute *attr,
+				       const char *buf, size_t count)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct eeh_dev *edev = pci_dev_to_eeh_dev(pdev);
+
+	if (!edev || !edev->pe)
+		return -ENODEV;
+
+	if (eeh_ops->notify_resume(pci_get_pdn(pdev)))
+		return -EIO;
+	return count;
+}
+static DEVICE_ATTR_RW(eeh_notify_resume);
+#endif
+
 void eeh_sysfs_add_device(struct pci_dev *pdev)
 {
 	struct eeh_dev *edev = pci_dev_to_eeh_dev(pdev);
@@ -104,7 +136,13 @@ void eeh_sysfs_add_device(struct pci_dev *pdev)
 	rc += device_create_file(&pdev->dev, &dev_attr_eeh_mode);
 	rc += device_create_file(&pdev->dev, &dev_attr_eeh_pe_config_addr);
 	rc += device_create_file(&pdev->dev, &dev_attr_eeh_pe_state);
-
+#ifdef CONFIG_PCI_IOV
+	if (of_get_property(pci_device_to_OF_node
+			    ((pdev->is_physfn ? pdev : pdev->physfn)),
+			    "ibm,is-open-sriov-pf", NULL))
+		rc += device_create_file(&pdev->dev,
+					 &dev_attr_eeh_notify_resume);
+#endif
 	if (rc)
 		pr_warn("EEH: Unable to create sysfs entries\n");
 	else if (edev)
@@ -128,6 +166,12 @@ void eeh_sysfs_remove_device(struct pci_dev *pdev)
 	device_remove_file(&pdev->dev, &dev_attr_eeh_mode);
 	device_remove_file(&pdev->dev, &dev_attr_eeh_pe_config_addr);
 	device_remove_file(&pdev->dev, &dev_attr_eeh_pe_state);
+#ifdef CONFIG_PCI_IOV
+	if (of_get_property(pci_device_to_OF_node
+			    ((pdev->is_physfn ? pdev : pdev->physfn)),
+			    "ibm,is-open-sriov-pf", NULL))
+		device_remove_file(&pdev->dev, &dev_attr_eeh_notify_resume);
+#endif
 
 	if (edev)
 		edev->mode &= ~EEH_DEV_SYSFS;
Signature · 1 line
2.14.3 (Apple Git-98)
#13 lore raw

PATCH v2 6/7 pseries/pci: Associate PEs to VFs in configure SR-IOV

In reply to Bryant G. Ly

After initial validation of SR-IOV resources, firmware will associate PEs to the dynamic VFs created within this call. This patch adds the association of PEs to the PF array of PE numbers indexed by VF.

---
 arch/powerpc/platforms/pseries/pci.c | 151 ++++++++++++++++++++++++++++++++++-
 1 file changed, 148 insertions(+), 3 deletions(-)
arch/powerpc/platforms/pseries/pci.c +148 -3
index 48d3af026f90..00e6475004ff 100644
@@ -57,18 +57,163 @@ void pcibios_name_device(struct pci_dev *dev)
 }
 DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pcibios_name_device);
 #endif
-
 #ifdef CONFIG_PCI_IOV
+#define MAX_VFS_FOR_MAP_PE 256
+struct pe_map_bar_entry {
+	__be64     bar;       /* Input:  Virtual Function BAR */
+	__be16     rid;       /* Input:  Virtual Function Router ID */
+	__be16     pe_num;    /* Output: Virtual Function PE Number */
+	__be32     reserved;  /* Reserved Space */
+};
+
+int pseries_send_map_pe(struct pci_dev *pdev,
+			u16 num_vfs,
+			struct pe_map_bar_entry *vf_pe_array)
+{
+	struct pci_dn *pdn;
+	int rc;
+	unsigned long buid, addr;
+	int ibm_map_pes = rtas_token("ibm,open-sriov-map-pe-number");
+
+	if (ibm_map_pes == RTAS_UNKNOWN_SERVICE)
+		return -EINVAL;
+
+	pdn = pci_get_pdn(pdev);
+	addr = rtas_config_addr(pdn->busno, pdn->devfn, 0);
+	buid = pdn->phb->buid;
+	spin_lock(&rtas_data_buf_lock);
+	memcpy(rtas_data_buf, vf_pe_array,
+	       RTAS_DATA_BUF_SIZE);
+	rc = rtas_call(ibm_map_pes, 5, 1, NULL, addr,
+		       BUID_HI(buid), BUID_LO(buid),
+		       rtas_data_buf,
+		       num_vfs * sizeof(struct pe_map_bar_entry));
+	memcpy(vf_pe_array, rtas_data_buf, RTAS_DATA_BUF_SIZE);
+	spin_unlock(&rtas_data_buf_lock);
+
+	if (rc)
+		dev_err(&pdev->dev,
+			"%s: Failed to associate pes PE#%lx, rc=%x\n",
+			__func__,  addr, rc);
+
+	return rc;
+}
+
+void pseries_set_pe_num(struct pci_dev *pdev, u16 vf_index, __be16 pe_num)
+{
+	struct pci_dn *pdn;
+
+	pdn = pci_get_pdn(pdev);
+	pdn->pe_num_map[vf_index] = be16_to_cpu(pe_num);
+	dev_dbg(&pdev->dev, "VF %04x:%02x:%02x.%x associated with PE#%x\n",
+		pci_domain_nr(pdev->bus),
+		pdev->bus->number,
+		PCI_SLOT(pci_iov_virtfn_devfn(pdev, vf_index)),
+		PCI_FUNC(pci_iov_virtfn_devfn(pdev, vf_index)),
+		pdn->pe_num_map[vf_index]);
+}
+
+int pseries_associate_pes(struct pci_dev *pdev, u16 num_vfs)
+{
+	struct pci_dn *pdn;
+	int i, rc, vf_index;
+	struct pe_map_bar_entry *vf_pe_array;
+	struct resource *res;
+	u64 size;
+
+	vf_pe_array = kzalloc(RTAS_DATA_BUF_SIZE, GFP_KERNEL);
+	if (!vf_pe_array)
+		return -ENOMEM;
+
+	pdn = pci_get_pdn(pdev);
+	/* create firmware structure to associate pes */
+	for (vf_index = 0; vf_index < num_vfs; vf_index++) {
+		pdn->pe_num_map[vf_index] = IODA_INVALID_PE;
+		for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
+			res = &pdev->resource[i + PCI_IOV_RESOURCES];
+			if (!res->parent)
+				continue;
+			size = pcibios_iov_resource_alignment(pdev, i +
+					PCI_IOV_RESOURCES);
+			vf_pe_array[vf_index].bar =
+				cpu_to_be64(res->start + size * vf_index);
+			vf_pe_array[vf_index].rid =
+				cpu_to_be16((pci_iov_virtfn_bus(pdev, vf_index)
+					    << 8) | pci_iov_virtfn_devfn(pdev,
+					    vf_index));
+			vf_pe_array[vf_index].pe_num =
+				cpu_to_be16(IODA_INVALID_PE);
+		}
+	}
+
+	rc = pseries_send_map_pe(pdev, num_vfs, vf_pe_array);
+	/* Only zero is success */
+	if (!rc)
+		for (vf_index = 0; vf_index < num_vfs; vf_index++)
+			pseries_set_pe_num(pdev, vf_index,
+					   vf_pe_array[vf_index].pe_num);
+
+	kfree(vf_pe_array);
+	return rc;
+}
+
+int pseries_pci_sriov_enable(struct pci_dev *pdev, u16 num_vfs)
+{
+	struct pci_dn         *pdn;
+	int                    rc;
+	const int *max_vfs;
+	int max_config_vfs;
+	struct device_node *dn = pci_device_to_OF_node(pdev);
+
+	max_vfs = of_get_property(dn, "ibm,number-of-configurable-vfs", NULL);
+
+	if (!max_vfs)
+		return -EINVAL;
+
+	/* First integer stores max config */
+	max_config_vfs = of_read_number(&max_vfs[0], 1);
+	if (max_config_vfs < num_vfs && num_vfs > MAX_VFS_FOR_MAP_PE) {
+		dev_err(&pdev->dev,
+			"Num VFs %x > %x Configurable VFs\n",
+			num_vfs, (num_vfs > MAX_VFS_FOR_MAP_PE) ?
+			MAX_VFS_FOR_MAP_PE : max_config_vfs);
+		return -EINVAL;
+	}
+
+	pdn = pci_get_pdn(pdev);
+	pdn->pe_num_map = kmalloc_array(num_vfs,
+					sizeof(*pdn->pe_num_map),
+					GFP_KERNEL);
+	if (!pdn->pe_num_map)
+		return -ENOMEM;
+
+	rc = pseries_associate_pes(pdev, num_vfs);
+
+	/* Anything other than zero is failure */
+	if (rc) {
+		dev_err(&pdev->dev, "Failure to enable sriov: %x\n", rc);
+		kfree(pdn->pe_num_map);
+	} else {
+		pci_vf_drivers_autoprobe(pdev, false);
+	}
+
+	return rc;
+}
+
 int pseries_pcibios_sriov_enable(struct pci_dev *pdev, u16 num_vfs)
 {
 	/* Allocate PCI data */
 	add_dev_pci_data(pdev);
-	pci_vf_drivers_autoprobe(pdev, false);
-	return 0;
+	return pseries_pci_sriov_enable(pdev, num_vfs);
 }
 
 int pseries_pcibios_sriov_disable(struct pci_dev *pdev)
 {
+	struct pci_dn         *pdn;
+
+	pdn = pci_get_pdn(pdev);
+	/* Releasing pe_num_map */
+	kfree(pdn->pe_num_map);
 	/* Release PCI data */
 	remove_dev_pci_data(pdev);
 	pci_vf_drivers_autoprobe(pdev, true);
Signature · 1 line
2.14.3 (Apple Git-98)
#14 lore raw

PATCH v2 7/7 pseries/setup: Add Initialization of VF Bars

In reply to Bryant G. Ly

When enabling SR-IOV in pseries platform,
the VF bar properties for a PF are reported on the device node in the device tree.

This patch adds the IOV Bar resources to Linux structures from the device tree for later use when configuring SR-IOV by PF driver.

---
 arch/powerpc/include/asm/pci.h         |   2 +
 arch/powerpc/kernel/pci_of_scan.c      |   2 +-
 arch/powerpc/platforms/pseries/setup.c | 167 +++++++++++++++++++++++++++++++++
 3 files changed, 170 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/pci.h +2 -0
index 8dc32eacc97c..d82802ff5088 100644
@@ -121,6 +121,8 @@ extern int remove_phb_dynamic(struct pci_controller *phb);
 extern struct pci_dev *of_create_pci_dev(struct device_node *node,
 					struct pci_bus *bus, int devfn);
 
+extern unsigned int pci_parse_of_flags(u32 addr0, int bridge);
+
 extern void of_scan_pci_bridge(struct pci_dev *dev);
 
 extern void of_scan_bus(struct device_node *node, struct pci_bus *bus);
arch/powerpc/kernel/pci_of_scan.c +1 -1
index 0d790f8432d2..20ceec4a5f5e 100644
@@ -38,7 +38,7 @@ static u32 get_int_prop(struct device_node *np, const char *name, u32 def)
  * @addr0: value of 1st cell of a device tree PCI address.
  * @bridge: Set this flag if the address is from a bridge 'ranges' property
  */
-static unsigned int pci_parse_of_flags(u32 addr0, int bridge)
+unsigned int pci_parse_of_flags(u32 addr0, int bridge)
 {
 	unsigned int flags = 0;
 
arch/powerpc/platforms/pseries/setup.c +167 -0

179 lines not on this page · raw message

Signature · 1 line
2.14.3 (Apple Git-98)