CXL: Add image control to sysfs
Subsystems (2)
PATCH 1/3 CXL: Add image control to sysfs
reset_image_select identifies whether a PERST will cause the image to be flashed to the card. And if so, which image.
Valid entries are: "none", "user" and "factory".
A value of "none" means PERST will not cause the image to be flashed. A power cycle to the pcie slot is required to load the image.
"user" loads the user provided image and "factory" loads the factory image upon PERST.
sysfs updates the cxl struct in the driver then calls cxl_update_image_control to write the vals in the VSEC.
--- Documentation/ABI/testing/sysfs-class-cxl | 9 +++++++ drivers/misc/cxl/cxl.h | 1 + drivers/misc/cxl/pci.c | 35 +++++++++++++++++++++++++++ drivers/misc/cxl/sysfs.c | 39 +++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+)
Documentation/ABI/testing/sysfs-class-cxl +9 -0
@@ -127,3 +127,12 @@ Contact: [email protected] Description: read only Will return "user" or "factory" depending on the image loaded onto the card. + +What: /sys/class/cxl/<card>/load_image_on_perst +Date: December 2014 +Contact: [email protected] +Description: read/write + Value of "none" means PERST will not cause image to be loaded + to the card. A power cycle is required to load the image. + Value of "user" and "factory" means PERST will cause either the + user or factory image to be loaded.
drivers/misc/cxl/cxl.h +1 -0
@@ -488,6 +488,7 @@ void cxl_release_one_irq(struct cxl *adapter, int hwirq);int cxl_alloc_irq_ranges (struct cxl_irq_ranges *irqs,struct cxl *adapter,unsigned int num);void cxl_release_irq_ranges (struct cxl_irq_ranges *irqs,struct cxl *adapter);int cxl_setup_irq (struct cxl *adapter,unsigned int hwirq,unsigned int virq); +int cxl_update_image_control (struct cxl *adapter);/* common == phyp + powernv */ struct cxl_process_element_common {
drivers/misc/cxl/pci.c +35 -0
@@ -362,6 +362,41 @@ int cxl_setup_irq(struct cxl *adapter, unsigned int hwirq,return pnv_cxl_ioda_msi_setup (dev, hwirq, virq); } +int cxl_update_image_control (struct cxl *adapter) +{ +struct pci_dev *dev =to_pci_dev (adapter->dev.parent); +int rc; +int vsec; +u8 image_state; + +if (!(vsec =find_cxl_vsec (dev))) { +dev_err (&dev->dev,"ABORTING: CXL VSEC not found!\n" ); +return -ENODEV ; + } + +if ((rc =CXL_READ_VSEC_IMAGE_STATE (dev, vsec, &image_state))) { +dev_err (&dev->dev,"failed to read image state: %i\n" , rc); +return rc; + } + +if (adapter->perst_loads_image) + image_state |=CXL_VSEC_PERST_LOADS_IMAGE ; +else + image_state &= ~CXL_VSEC_PERST_LOADS_IMAGE ; + +if (adapter->perst_select_user) + image_state |=CXL_VSEC_PERST_SELECT_USER ; +else + image_state &= ~CXL_VSEC_PERST_SELECT_USER ; + +if ((rc =CXL_WRITE_VSEC_IMAGE_STATE (dev, vsec, image_state))) { +dev_err (&dev->dev,"failed to update image control: %i\n" , rc); +return rc; + } + +return 0 ; +} +int cxl_alloc_one_irq (struct cxl *adapter) {struct pci_dev *dev =to_pci_dev (adapter->dev.parent);
drivers/misc/cxl/sysfs.c +39 -0
@@ -56,11 +56,50 @@ static ssize_t image_loaded_show(struct device *device,return scnprintf (buf,PAGE_SIZE ,"factory\n" ); } +static ssize_t load_image_on_perst_show (struct device *device, +struct device_attribute *attr, +char *buf) +{ +struct cxl *adapter =to_cxl_adapter (device); + +if (!adapter->perst_loads_image) +return scnprintf (buf,PAGE_SIZE ,"none\n" ); + +if (adapter->perst_select_user) +return scnprintf (buf,PAGE_SIZE ,"user\n" ); +return scnprintf (buf,PAGE_SIZE ,"factory\n" ); +} + +static ssize_t load_image_on_perst_store (struct device *device, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct cxl *adapter =to_cxl_adapter (device); +int rc; + +if (!strncmp (buf,"none" ,4 )) + adapter->perst_loads_image = false; +else if (!strncmp (buf,"user" ,4 )) { + adapter->perst_select_user = true; + adapter->perst_loads_image = true; + }else if (!strncmp (buf,"factory" ,7 )) { + adapter->perst_select_user = false; + adapter->perst_loads_image = true; + }else +return -EINVAL ; + +if ((rc =cxl_update_image_control (adapter))) +return rc; + +return count; +} +static struct device_attribute adapter_attrs[] = {__ATTR_RO (caia_version),__ATTR_RO (psl_revision),__ATTR_RO (base_image),__ATTR_RO (image_loaded), +__ATTR_RW (load_image_on_perst), };
Signature · 1 line
1.9.1
PATCH 2/3 CXL: Enable CAPP recovery
Turning snoops on is the last step in CAPP recovery. Sapphire is expected to have reinitialized the PHB and done the previous recovery steps.
Add mode argument to opal call to do this. Driver can turn snoops off although it does not currently.
--- arch/powerpc/include/asm/opal.h | 8 ++++++++ arch/powerpc/include/asm/pnv-pci.h | 2 +- arch/powerpc/platforms/powernv/pci-ioda.c | 6 +++--- drivers/misc/cxl/pci.c | 8 +++++++- 4 files changed, 19 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/opal.h +8 -0
@@ -595,6 +595,14 @@ enum {OPAL_PHB3_NUM_PEST_REGS =256 }; +/* CAPI modes for PHB */ +enum { +OPAL_PHB_CAPI_MODE_PCIE =0 , +OPAL_PHB_CAPI_MODE_CAPI =1 , +OPAL_PHB_CAPI_MODE_SNOOP_OFF =2 , +OPAL_PHB_CAPI_MODE_SNOOP_ON =3 , +}; +struct OpalIoPhbErrorCommon {__be32 version;__be32 ioType;
arch/powerpc/include/asm/pnv-pci.h +1 -1
@@ -13,7 +13,7 @@#include <linux/pci.h> #include <misc/cxl.h> -int pnv_phb_to_cxl (struct pci_dev *dev); +int pnv_phb_to_cxl_mode (struct pci_dev *dev,uint64_t mode);int pnv_cxl_ioda_msi_setup (struct pci_dev *dev,unsigned int hwirq,unsigned int virq);int pnv_cxl_alloc_hwirqs (struct pci_dev *dev,int num);
arch/powerpc/platforms/powernv/pci-ioda.c +3 -3
@@ -1468,7 +1468,7 @@ struct device_node *pnv_pci_to_phb_node(struct pci_dev *dev) }EXPORT_SYMBOL (pnv_pci_to_phb_node); -int pnv_phb_to_cxl (struct pci_dev *dev) +int pnv_phb_to_cxl_mode (struct pci_dev *dev,uint64_t mode) {struct pci_controller *hose =pci_bus_to_host (dev->bus);struct pnv_phb *phb = hose->private_data;
@@ -1481,13 +1481,13 @@ int pnv_phb_to_cxl(struct pci_dev *dev)pe_info (pe,"Switching PHB to CXL\n" ); - rc =opal_pci_set_phb_cxl_mode (phb->opal_id,1 , pe->pe_number); + rc =opal_pci_set_phb_cxl_mode (phb->opal_id, mode, pe->pe_number);if (rc)dev_err (&dev->dev,"opal_pci_set_phb_cxl_mode failed: %i\n" , rc);return rc; } -EXPORT_SYMBOL (pnv_phb_to_cxl); +EXPORT_SYMBOL (pnv_phb_to_cxl_mode);/* Find PHB for cxl dev and allocate MSI hwirqs? * Returns the absolute hardware IRQ number
drivers/misc/cxl/pci.c +7 -1
@@ -924,9 +924,15 @@ static struct cxl *cxl_init_adapter(struct pci_dev *dev)if ((rc =init_implementation_adapter_regs (adapter, dev))) goto err3; -if ((rc =pnv_phb_to_cxl (dev))) +if ((rc =pnv_phb_to_cxl_mode (dev,OPAL_PHB_CAPI_MODE_CAPI ))) goto err3; +/* If recovery happened, the last step is to turn on snooping. +* In the non-recovery case this has no effect */ +if ((rc =pnv_phb_to_cxl_mode (dev,OPAL_PHB_CAPI_MODE_SNOOP_ON ))) { + goto err3; + } +if ((rc =cxl_register_psl_err_irq (adapter))) goto err3;
Signature · 1 line
1.9.1
Re: [PATCH 2/3] CXL: Enable CAPP recovery
PATCH 3/3 CXL: Add ability to reset the card
In reply to Ryan GrimmAdds reset to sysfs which will PERST the card. If load_image_on_perst is set to "user" or "factory", the PERST will cause that image to be loaded.
load_image_on_perst is set to "user" for production.
"none" could be used for debugging. The PSL trace arrays are preserved which then can be read through debugfs.
PERST also triggers CAPP recovery. An HMI comes in, which is handled by EEH. EEH unbinds the driver, calls into Sapphire to reinitialize the PHB, then rebinds the driver.
--- Documentation/ABI/testing/sysfs-class-cxl | 14 ++++++++-- drivers/misc/cxl/cxl.h | 1 + drivers/misc/cxl/pci.c | 44 +++++++++++++++++++++++++++++-- drivers/misc/cxl/sysfs.c | 13 +++++++++ 4 files changed, 68 insertions(+), 4 deletions(-)
Documentation/ABI/testing/sysfs-class-cxl +12 -2
@@ -133,6 +133,16 @@ Date: December 2014 Contact: [email protected] Description: read/write Value of "none" means PERST will not cause image to be loaded - to the card. A power cycle is required to load the image. + to the card. A power cycle is required to load the image. + "none" is useful for debugging so the contents of the trace + arrays are preserved. Value of "user" and "factory" means PERST will cause either the - user or factory image to be loaded. + user or factory image to be loaded. "user" is default and + should be used in production. + +What: /sys/class/cxl/<card>/reset +Date: October 2014 +Contact: [email protected] +Description: write only + Writing 1 will issue a PERST to card which may cause the card + to reload the FPGA depending on load_image_on_perst.
drivers/misc/cxl/cxl.h +1 -0
@@ -489,6 +489,7 @@ int cxl_alloc_irq_ranges(struct cxl_irq_ranges *irqs, struct cxl *adapter, unsigvoid cxl_release_irq_ranges (struct cxl_irq_ranges *irqs,struct cxl *adapter);int cxl_setup_irq (struct cxl *adapter,unsigned int hwirq,unsigned int virq);int cxl_update_image_control (struct cxl *adapter); +int cxl_reset (struct cxl *adapter);/* common == phyp + powernv */ struct cxl_process_element_common {
drivers/misc/cxl/pci.c +42 -2
68 lines not on this page · raw message
drivers/misc/cxl/sysfs.c +13 -0
@@ -56,6 +56,18 @@ static ssize_t image_loaded_show(struct device *device,return scnprintf (buf,PAGE_SIZE ,"factory\n" ); } +static ssize_t reset_adapter_store (struct device *device, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct cxl *adapter =to_cxl_adapter (device); +int rc; + +if ((rc =cxl_reset (adapter))) +return rc; +return count; +} +static ssize_t load_image_on_perst_show (struct device *device,struct device_attribute *attr,char *buf)
@@ -100,6 +112,7 @@ static struct device_attribute adapter_attrs[] = {__ATTR_RO (base_image),__ATTR_RO (image_loaded),__ATTR_RW (load_image_on_perst), + __ATTR(reset, S_IWUSR, NULL, reset_adapter_store), };
Signature · 1 line
1.9.1
Re: [PATCH 3/3] CXL: Add ability to reset the card
Hi Ryan,
Excerpts from Ryan Grimm's message of 2015-01-16 09:27:17 +1100:
Quoted 4 lines
Adds reset to sysfs which will PERST the card. If
load_image_on_perstis set to "user" or "factory", the PERST will cause that image to be loaded.
load_image_on_perstis set to "user" for production.
While it generally will be "user" for production, some cards may only ship with only a factory image, which is then going to be the image used for production. It might be better to say that it will default to whichever image the card has already loaded.
Documentation/ABI/testing/sysfs-class-cxl Date: December 2014 · line 141
Quoted 9 lines
Value of "none" means PERST will not cause image to be loaded
Documentation/ABI/testing/sysfs-class-cxl +5
-2- to the card. A power cycle is required to load the image. + to the card. A power cycle is required to load the image. + "none" is useful for debugging so the contents of the trace + arrays are preserved. Value of "user" and "factory" means PERST will cause either the - user or factory image to be loaded. + user or factory image to be loaded. "user" is default and + should be used in production.
git am spotted some whitespace at the end of a couple of lines here
drivers/misc/cxl/pci.c static void cxl_remove_afu(struct cxl_afu *afu) · line 769
Quoted 12 lines
drivers/misc/cxl/pci.c +12
-0+/* pcie_warm_reset requests a fundamental pci reset which includes a +* PERST assert/deassert. PERST triggers a loading of the image +* if "user" or "factory" is selected in sysfs */ +if ((rc =pci_set_pcie_reset_state (dev, pcie_warm_reset))) { +dev_err (&dev->dev,"cxl: pcie_warm_reset failed\n" ); +return rc; + } + +/* the PERST done above fences the PHB. So, reset depends on EEH +* to unbind the driver, tell Sapphire to reinit the PHB, and rebind +* the driver. Do an mmio read explictly to ensure EEH notices the +* fenced PHB. Retry for a few seconds before giving up. */
Great, thanks for adding the explanations here :)
Quoted 8 lines
drivers/misc/cxl/pci.c +2
-2@@ -806,8 +843,8 @@ static int cxl_read_vsec(struct cxl *adapter, struct pci_dev *dev)CXL_READ_VSEC_BASE_IMAGE (dev, vsec, &adapter->base_image);CXL_READ_VSEC_IMAGE_STATE (dev, vsec, &image_state); adapter->user_image_loaded = !!(image_state &CXL_VSEC_USER_IMAGE_LOADED ); - adapter->perst_loads_image = !!(image_state &CXL_VSEC_PERST_LOADS_IMAGE ); - adapter->perst_select_user = !!(image_state &CXL_VSEC_PERST_SELECT_USER ); + adapter->perst_loads_image = true; + adapter->perst_select_user = !!(image_state &CXL_VSEC_USER_IMAGE_LOADED );
<snip>
drivers/misc/cxl/pci.c static struct cxl *cxl_init_adapter(struct pci_dev *dev) · line 956
Quoted 2 lines
drivers/misc/cxl/pci.c +2
-0+if ((rc =cxl_update_image_control (adapter))) + goto err2;
Please move these two hunks into a separate patch (can be first in the series) along with the cxl_update_image_control() function from patch 1
- I'd like to get this backported to stable, which will be simpler if it is in it's own patch.
drivers/misc/cxl/sysfs.c static ssize_t image_loaded_show(struct device *device, · line 69
Quoted 11 lines
drivers/misc/cxl/sysfs.c +11
-0+static ssize_t reset_adapter_store (struct device *device, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct cxl *adapter =to_cxl_adapter (device); +int rc; + +if ((rc =cxl_reset (adapter))) +return rc; +return count; +}
Please add a check here so the reset only occurs when a "1" is written to this file to match the documentation.
Cheers,
-Ian
Re: [PATCH 3/3] CXL: Add ability to reset the card
Quoted 6 lines · Ian Munsie
Hi Ryan,
Excerpts from Ryan Grimm's message of 2015-01-16 09:27:17 +1100:
Quoted 3 lines
Adds reset to sysfs which will PERST the card. If
load_image_on_perstis set to "user" or "factory", the PERST will cause that image to be loaded.
Quoted 6 lines
Quoted 1 line
load_image_on_perstis set to "user" for production.While it generally will be "user" for production, some cards may only ship with only a factory image, which is then going to be the image used for production. It might be better to say that it will default to whichever image the card has already loaded.
K, yeah.
Quoted 12 lines
Documentation/ABI/testing/sysfs-class-cxl Date: December 2014 · line 141
Quoted 11 lines
Value of "none" means PERST will not cause image to be loaded
Documentation/ABI/testing/sysfs-class-cxl +5
-2- to the card. A power cycle is required to load the image. + to the card. A power cycle is required to load the image. + "none" is useful for debugging so the contents of the trace + arrays are preserved. Value of "user" and "factory" means PERST will cause either the - user or factory image to be loaded. + user or factory image to be loaded. "user" is default and + should be used in production.
Quoted 2 lines
git am spotted some whitespace at the end of a couple of lines here
Fixed...darn whitespace.
Quoted 27 lines
Quoted 4 lines
drivers/misc/cxl/pci.c +2
-0+/* pcie_warm_reset requests a fundamental pci reset which includes a +* PERST assert/deassert. PERST triggers a loading of the image drivers/misc/cxl/pci.c static void cxl_remove_afu(struct cxl_afu *afu) · line 769
Quoted 10 lines
drivers/misc/cxl/pci.c +10
-0+* if "user" or "factory" is selected in sysfs */ +if ((rc =pci_set_pcie_reset_state (dev, pcie_warm_reset))) { +dev_err (&dev->dev,"cxl: pcie_warm_reset failed\n" ); +return rc; + } + +/* the PERST done above fences the PHB. So, reset depends on EEH +* to unbind the driver, tell Sapphire to reinit the PHB, and rebind +* the driver. Do an mmio read explictly to ensure EEH notices the +* fenced PHB. Retry for a few seconds before giving up. */ Great, thanks for adding the explanations here :)
Quoted 8 lines
drivers/misc/cxl/pci.c +2
-2@@ -806,8 +843,8 @@ static int cxl_read_vsec(struct cxl *adapter, struct pci_dev *dev)CXL_READ_VSEC_BASE_IMAGE (dev, vsec, &adapter->base_image);CXL_READ_VSEC_IMAGE_STATE (dev, vsec, &image_state); adapter->user_image_loaded = !!(image_state &CXL_VSEC_USER_IMAGE_LOADED ); - adapter->perst_loads_image = !!(image_state &CXL_VSEC_PERST_LOADS_IMAGE ); - adapter->perst_select_user = !!(image_state &CXL_VSEC_PERST_SELECT_USER ); + adapter->perst_loads_image = true; + adapter->perst_select_user = !!(image_state &CXL_VSEC_USER_IMAGE_LOADED );<snip>
Quoted 9 lines
drivers/misc/cxl/pci.c static struct cxl *cxl_init_adapter(struct pci_dev *dev) · line 956
Quoted 2 lines
drivers/misc/cxl/pci.c +2
-0+if ((rc =cxl_update_image_control (adapter))) + goto err2;Please move these two hunks into a separate patch (can be first in the series) along with the
cxl_update_image_control()function from patch 1
- I'd like to get this backported to stable, which will be simpler if it is in it's own patch.
K, I completely agree.
Quoted 6 lines
Quoted 6 lines
drivers/misc/cxl/sysfs.c +6
-0+static ssize_t reset_adapter_store (struct device *device, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct cxl *adapter =to_cxl_adapter (device); +int rc;
Quoted 9 lines
drivers/misc/cxl/sysfs.c static ssize_t image_loaded_show(struct device *device, · line 69
Quoted 5 lines
drivers/misc/cxl/sysfs.c +5
-0+ +if ((rc =cxl_reset (adapter))) +return rc; +return count; +}Please add a check here so the reset only occurs when a "1" is written to this file to match the documentation.
Yeah, it's probably good to do that :)
-Ryan
Quoted 4 lines
Cheers,
-Ian
Hi Ryan,
Excerpts from Ryan Grimm's message of 2015-01-16 09:27:15 +1100:
Quoted 1 line
reset_image_selectidentifies whether a PERST will cause the image to be
s/reset_image_select/load_image_on_perst/
Documentation/ABI/testing/sysfs-class-cxl Contact: [email protected] · line 136
Quoted 6 lines
Documentation/ABI/testing/sysfs-class-cxl +6
-0+What: /sys/class/cxl/<card>/load_image_on_perst +Date: December 2014 +Contact: [email protected] +Description: read/write + Value of "none" means PERST will not cause image to be loaded + to the card. A power cycle is required to load the image.
git am spotted some whitespace at the end of this line.
Quoted 1 line
+int
cxl_update_image_control(struct cxl *adapter)
Would you be able to pull this function out into a separate patch (can be first in the series so everything still compiles after each patch) along with the change to the image_state defaults from patch 3? It's a fix that I think would be good to be backported to stable, which will be simpler if it's in a separate patch.
Otherwise, looks good :)
Quoted 7 lines · Ian Munsie
Hi Ryan,
Excerpts from Ryan Grimm's message of 2015-01-16 09:27:15 +1100:
Quoted 1 line
reset_image_selectidentifies whether a PERST will cause the image to bes/reset_image_select/load_image_on_perst/
Ah, thanks, fixed.
Quoted 10 lines
Documentation/ABI/testing/sysfs-class-cxl Contact: [email protected] · line 136
Quoted 6 lines
Documentation/ABI/testing/sysfs-class-cxl +6
-0+What: /sys/class/cxl/<card>/load_image_on_perst +Date: December 2014 +Contact: [email protected] +Description: read/write + Value of "none" means PERST will not cause image to be loaded + to the card. A power cycle is required to load the image.git am spotted some whitespace at the end of this line.
Thanks, fixed again.
Quoted 8 lines
Quoted 1 line
+int
cxl_update_image_control(struct cxl *adapter)Would you be able to pull this function out into a separate patch (can be first in the series so everything still compiles after each patch) along with the change to the
image_statedefaults from patch 3? It's a fix that I think would be good to be backported to stable, which will be simpler if it's in a separate patch.
Good idea. Yeah, pulling in the change from patch 3 makes sense.
Sure, done.
Quoted 3 lines
Otherwise, looks good :)
Great, thanks for reviewing!~
-Ryan
Quoted 3 lines
Acked-by Ian Munsie <[email protected]>