Subject: [PATCH 0/2] PCI/CXL: Recover CXL Downstream Ports from PM Init failure
CXL r4.0 sec 8.1.5.1 Implementation Note describes a scenario in which a Secondary Bus Reset, a Link Down, or Downstream Port Containment on a CXL Downstream Port prevents Port PM Init from completing when ACS Source Validation is enabled on the Downstream Port. The spec states that another SBR alone does not recover the port and describes a software recovery sequence.
Patch 1 extends cxl_reset_bus_function(), the helper backing the cxl_bus PCI/CXL reset method exposed to userspace via sysfs. It saves, clears, and restores ACS Source Validation and Bus Master Enable on the CXL Downstream Port around the SBR it issues. This keeps the userspace cxl_bus reset path from leaving the port unable to complete PM Init.
Patch 2 adds a recovery pass during CXL enumeration. For each CXL Downstream Port in a memdev's ancestry, the CXL core checks whether PM Init has completed. If it has not, regardless of what caused the failure, it invokes cxl_reset_bus_function() on the child below the port in the hope of restoring the port to a usable state. CXL enumeration re-runs after events that tear down and re-probe the memdev, including DPC, AER, and Link Down, so those paths reach this recovery.
This small series is developed from an old RFC v3:
https://lore.kernel.org/linux-cxl/[email protected]/
Fabio M. De Francesco (2):
PCI/CXL: Allow PM Init to complete on cxl_bus reset if ACS SV enabled cxl/core: Recover from PM Init failure via cxl_reset_bus_function()
drivers/cxl/core/pci.c | 30 ++++++++++++++++++++
drivers/cxl/core/port.c | 22 +++++++++++++++ drivers/cxl/cxlpci.h | 3 ++ drivers/pci/pci.c | 52 ++++++++++++++++++++++++++++++++++- include/linux/pci.h | 1 + include/uapi/linux/pci_regs.h | 2 ++ 6 files changed, 109 insertions(+), 1 deletion(-)
Signature · 1 line
2.53.0
PATCH 1/2 PCI/CXL: Allow PM Init to complete on cxl_bus reset if ACS SV enabled
CXL r4.0 sec 8.1.5.1 Implementation Note describes a scenario in which issuing a Secondary Bus Reset on a CXL Downstream Port leaves the Port Power Management Initialization Complete bit unset when the PCIe Access Control Service (ACS) Source Validation bit (SV) is enabled on the Downstream Port. The spec states that another SBR alone will not facilitate recovery and shows a software recovery sequence.
Implement the sequence by extending cxl_reset_bus_function() to save, clear, and restore ACS SV and Bus Master Enable (BME) on the Downstream Port around the SBR with the use of helpers.
The wait inside pci_bridge_secondary_bus_reset() covers the 100 ms referenced by the spec. The helpers return when ACS SV is not enabled on the Downstream Port.
--- drivers/pci/pci.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
drivers/pci/pci.c +49 -0
@@ -4930,10 +4930,55 @@ static int pci_reset_bus_function(struct pci_dev *dev, bool probe)return rc; } +static void cxl_disable_acs_sv_bme (struct pci_dev *bridge,u16 *saved_cmd, +u16 *saved_acs_ctrl) +{ +if (!bridge->acs_cap) +return ; + +pci_read_config_word (bridge, bridge->acs_cap +PCI_ACS_CTRL , + saved_acs_ctrl); +if (!(*saved_acs_ctrl &PCI_ACS_SV )) +return ; + +pci_read_config_word (bridge,PCI_COMMAND , saved_cmd); +if (*saved_cmd &PCI_COMMAND_MASTER ) +pci_clear_master (bridge); + +pci_write_config_word (bridge, bridge->acs_cap +PCI_ACS_CTRL , + *saved_acs_ctrl & ~PCI_ACS_SV ); +} + +static void cxl_restore_acs_sv_bme (struct pci_dev *bridge,u16 saved_cmd, +u16 saved_acs_ctrl) +{ +if (!bridge->acs_cap || !(saved_acs_ctrl &PCI_ACS_SV )) +return ; + +pci_write_config_word (bridge, bridge->acs_cap +PCI_ACS_CTRL , + saved_acs_ctrl); +if (saved_cmd &PCI_COMMAND_MASTER ) +pci_set_master (bridge); +} + +/** +* cxl_reset_bus_function - SBR for a child of a CXL downstream port +* @dev: child device whose upstream bridge is a CXL downstream port +* @probe: if true, only check whether the reset is supported +* +* Issues an SBR on @dev's parent bus. Temporarily sets the CXL Port +* DVSEC Unmask SBR bit across the reset. When ACS Source Validation +* is enabled on the bridge, also temporarily clears Bus Master Enable +* and ACS Source Validation, per CXL r4.0 sec 8.1.5.1. +* +* Return: 0 on success, -ENOTTY if the reset cannot be issued, or an +* errno from the reset path. +*/ static int cxl_reset_bus_function (struct pci_dev *dev,bool probe) {struct pci_dev *bridge;u16 dvsec, reg, val; +u16 saved_cmd =0 , saved_acs_ctrl =0 ;int rc; bridge =pci_upstream_bridge (dev);
@@ -4957,6 +5002,8 @@ static int cxl_reset_bus_function(struct pci_dev *dev, bool probe)return rc; } +cxl_disable_acs_sv_bme (bridge, &saved_cmd, &saved_acs_ctrl); +if (reg &PCI_DVSEC_CXL_PORT_CTL_UNMASK_SBR ) { val = reg; }else {
@@ -4971,6 +5018,8 @@ static int cxl_reset_bus_function(struct pci_dev *dev, bool probe)pci_write_config_word (bridge, dvsec +PCI_DVSEC_CXL_PORT_CTL , reg); +cxl_restore_acs_sv_bme (bridge, saved_cmd, saved_acs_ctrl); +pci_dev_reset_iommu_done (dev);return rc; }
Signature · 1 line
2.53.0
Dave Jiang
maintainerRe: [PATCH 1/2] PCI/CXL: Allow PM Init to complete on cxl_bus reset if ACS SV enabled
Quoted 25 lines · Fabio M. De Francesco
CXL r4.0 sec 8.1.5.1 Implementation Note describes a scenario in which issuing a Secondary Bus Reset on a CXL Downstream Port leaves the Port Power Management Initialization Complete bit unset when the PCIe Access Control Service (ACS) Source Validation bit (SV) is enabled on the Downstream Port. The spec states that another SBR alone will not facilitate recovery and shows a software recovery sequence.
Implement the sequence by extending
cxl_reset_bus_function()to save, clear, and restore ACS SV and Bus Master Enable (BME) on the Downstream Port around the SBR with the use of helpers.The wait inside
pci_bridge_secondary_bus_reset()covers the 100 ms referenced by the spec. The helpers return when ACS SV is not enabled on the Downstream Port.Signed-off-by Fabio M. De Francesco <[email protected]>--- drivers/pci/pci.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)drivers/pci/pci.c +0
-0
drivers/pci/pci.c static int pci_reset_bus_function(struct pci_dev *dev, bool probe) · line 4934
Quoted 5 lines
drivers/pci/pci.c +2
-0@@ -4930,10 +4930,55 @@ static int pci_reset_bus_function(struct pci_dev *dev, bool probe)return rc; } +static void cxl_disable_acs_sv_bme (struct pci_dev *bridge,u16 *saved_cmd, +u16 *saved_acs_ctrl)
Maybe you can call this 'cxl_bus_reset_prep' and the restore one 'cxl_bus_reset_done'?
drivers/pci/pci.c static int pci_reset_bus_function(struct pci_dev *dev, bool probe) · line 4935
Quoted 1 line
drivers/pci/pci.c +1
-0+{
Should you return int and check if the two ptr passed in are valid?
drivers/pci/pci.c static int pci_reset_bus_function(struct pci_dev *dev, bool probe) · line 4937
Quoted 2 lines
drivers/pci/pci.c +2
-0+if (!bridge->acs_cap) +return ;
Returning here and the output parameters are not set. That is a problem when you try to restore with invalid values. Maybe -EOPNOTSUPP needs to be returned. Errno from this function should prevent the restore from being called.
drivers/pci/pci.c static int pci_reset_bus_function(struct pci_dev *dev, bool probe) · line 4942
Quoted 5 lines
drivers/pci/pci.c +5
-0+ +pci_read_config_word (bridge, bridge->acs_cap +PCI_ACS_CTRL , + saved_acs_ctrl); +if (!(*saved_acs_ctrl &PCI_ACS_SV )) +return ;
What is the caller suppose to do if PCI_ACS_SV is not set? Should you skip restore later?
drivers/pci/pci.c static int pci_reset_bus_function(struct pci_dev *dev, bool probe) · line 4945
Quoted 3 lines
drivers/pci/pci.c +3
-0+ +pci_read_config_word (bridge,PCI_COMMAND , saved_cmd); +if (*saved_cmd &PCI_COMMAND_MASTER )
If all you care is master bit enabled, maybe just write back a bool 'master_en'.
drivers/pci/pci.c static int pci_reset_bus_function(struct pci_dev *dev, bool probe) · line 4953
Quoted 8 lines
drivers/pci/pci.c +8
-0+pci_clear_master (bridge); + +pci_write_config_word (bridge, bridge->acs_cap +PCI_ACS_CTRL , + *saved_acs_ctrl & ~PCI_ACS_SV ); +} + +static void cxl_restore_acs_sv_bme (struct pci_dev *bridge,u16 saved_cmd, +u16 saved_acs_ctrl)
static void cxl_bus_reset_done(struct pci_dev *bridge, bool master_en, u16 acs_ctrl)
saved_ has no relevance to the function itself.
Come to think of it, why not create a local struct and pass that in as parameter for prep and done functions? That way in the future if there are other stuff that needs to be done, this can be more versatile.
struct cxl_reset_ctx {
u16 acs_ctrl;
bool master_en;
bool acs_restore;
};This way you can also set 'acs_restore' on completion of the prep function. And in the done function, you can check and return early if it's not set. That takes away the messiness of returning errno in the prep function and then needing to determine if you need to call the prep function or not.
DJ
Quoted 49 lines
drivers/pci/pci.c +28
-0+{ +if (!bridge->acs_cap || !(saved_acs_ctrl &PCI_ACS_SV )) +return ; + +pci_write_config_word (bridge, bridge->acs_cap +PCI_ACS_CTRL , + saved_acs_ctrl); +if (saved_cmd &PCI_COMMAND_MASTER ) +pci_set_master (bridge); +} + +/** +* cxl_reset_bus_function - SBR for a child of a CXL downstream port +* @dev: child device whose upstream bridge is a CXL downstream port +* @probe: if true, only check whether the reset is supported +* +* Issues an SBR on @dev's parent bus. Temporarily sets the CXL Port +* DVSEC Unmask SBR bit across the reset. When ACS Source Validation +* is enabled on the bridge, also temporarily clears Bus Master Enable +* and ACS Source Validation, per CXL r4.0 sec 8.1.5.1. +* +* Return: 0 on success, -ENOTTY if the reset cannot be issued, or an +* errno from the reset path. +*/ static int cxl_reset_bus_function (struct pci_dev *dev,bool probe) {struct pci_dev *bridge;u16 dvsec, reg, val; +u16 saved_cmd =0 , saved_acs_ctrl =0 ;int rc; bridge =pci_upstream_bridge (dev);@@ -4957,6 +5002,8 @@ static int cxl_reset_bus_function(struct pci_dev *dev, bool probe)return rc; } +cxl_disable_acs_sv_bme (bridge, &saved_cmd, &saved_acs_ctrl); +if (reg &PCI_DVSEC_CXL_PORT_CTL_UNMASK_SBR ) { val = reg; }else {@@ -4971,6 +5018,8 @@ static int cxl_reset_bus_function(struct pci_dev *dev, bool probe)pci_write_config_word (bridge, dvsec +PCI_DVSEC_CXL_PORT_CTL , reg); +cxl_restore_acs_sv_bme (bridge, saved_cmd, saved_acs_ctrl); +pci_dev_reset_iommu_done (dev);return rc; }
Re: [PATCH 1/2] PCI/CXL: Allow PM Init to complete on cxl_bus reset if ACS SV enabled
In reply to Fabio M. De FrancescoQuoted 7 lines · Fabio M. De Francesco
CXL r4.0 sec 8.1.5.1 Implementation Note describes a scenario in which issuing a Secondary Bus Reset on a CXL Downstream Port leaves the Port Power Management Initialization Complete bit unset when the PCIe Access Control Service (ACS) Source Validation bit (SV) is enabled on the Downstream Port. The spec states that another SBR alone will not facilitate recovery and shows a software recovery sequence.
Quoted 7 lines
Implement the sequence by extending
cxl_reset_bus_function()to save, clear, and restore ACS SV and Bus Master Enable (BME) on the Downstream Port around the SBR with the use of helpers.The wait inside
pci_bridge_secondary_bus_reset()covers the 100 ms referenced by the spec. The helpers return when ACS SV is not enabled on the Downstream Port.
When reposting, fix subject line of cover letter.
Quoted 8 lines
+ *
cxl_reset_bus_function- SBR for a child of a CXL downstream port
+ * @dev: child device whose upstream bridge is a CXL downstream port
+ * @probe: if true, only check whether the reset is supported
+ *
+ * Issues an SBR on @dev's parent bus. Temporarily sets the CXL Port
+ * DVSEC Unmask SBR bit across the reset. When ACS Source Validation
+ * is enabled on the bridge, also temporarily clears Bus Master Enable
+ * and ACS Source Validation, per CXL r4.0 sec 8.1.5.1.
Use imperative mood consistently. ("Issue ...", "Temporarily set ...").
Quoted 32 lines
+ * Return: 0 on success,
-ENOTTYif the reset cannot be issued, or an
+ * errno from the reset path.
+ */
static intcxl_reset_bus_function(struct pci_dev *dev, bool probe){drivers/pci/pci.c +5
-0struct pci_dev *bridge;u16 dvsec, reg, val; +u16 saved_cmd =0 , saved_acs_ctrl =0 ;int rc; bridge =pci_upstream_bridge (dev);@@ -4957,6 +5002,8 @@ static int cxl_reset_bus_function(struct pci_dev *dev, bool probe)return rc; } +cxl_disable_acs_sv_bme (bridge, &saved_cmd, &saved_acs_ctrl); +if (reg &PCI_DVSEC_CXL_PORT_CTL_UNMASK_SBR ) { val = reg; }else {@@ -4971,6 +5018,8 @@ static int cxl_reset_bus_function(struct pci_dev *dev, bool probe)pci_write_config_word (bridge, dvsec +PCI_DVSEC_CXL_PORT_CTL , reg); +cxl_restore_acs_sv_bme (bridge, saved_cmd, saved_acs_ctrl); +pci_dev_reset_iommu_done (dev);return rc; }Signature · 1 line
2.53.0
PATCH 2/2 cxl/core: Recover from PM Init failure via cxl_reset_bus_function()
In reply to Fabio M. De FrancescoCXL r4.0 sec 8.1.5.1 Implementation Note describes a scenario in which a Secondary Bus Reset, a Link Down, or Downstream Port Containment on a CXL Downstream Port prevents Port PM Init from completing when ACS Source Validation is enabled.
During CXL enumeration, for each CXL Downstream Port in a memdev's ancestry, check whether PM Init has completed. If it has not, invoke cxl_reset_bus_function() which is exported for use by CXL.
--- drivers/cxl/core/pci.c | 30 ++++++++++++++++++++++++++++++ drivers/cxl/core/port.c | 22 ++++++++++++++++++++++ drivers/cxl/cxlpci.h | 3 +++ drivers/pci/pci.c | 3 ++- include/linux/pci.h | 1 + include/uapi/linux/pci_regs.h | 2 ++ 6 files changed, 60 insertions(+), 1 deletion(-)
drivers/cxl/core/pci.c +30 -0
@@ -926,3 +926,33 @@ int cxl_port_get_possible_dports(struct cxl_port *port)return ctx.count; } + +/** +* cxl_port_pm_init_is_complete - check the downstream port's PM Init Complete +* @pdev: downstream port +* +* Read the Port Power Management Initialization Complete bit in the +* Downstream Port's CXL DVSEC Port Extended Status register. +* +* Return: false only when the bit is observably clear. Return true when PM +* init is complete, when @pdev is not a CXL port (no Port DVSEC), or when +* the status register cannot be read. +*/ +bool cxl_port_pm_init_is_complete (struct pci_dev *pdev) +{ +u16 status; +u16 dvsec; +int rc; + + dvsec =pci_find_dvsec_capability (pdev,PCI_VENDOR_ID_CXL , +PCI_DVSEC_CXL_PORT ); +if (!dvsec) +return true; + + rc =pci_read_config_word (pdev, dvsec +PCI_DVSEC_CXL_PORT_EXT_STATUS , + &status); +if (rc ||PCI_POSSIBLE_ERROR (status)) +return true; + +return !!FIELD_GET (PCI_DVSEC_CXL_PORT_EXT_STATUS_PM_INIT_COMP , status); +}
drivers/cxl/core/port.c +22 -0
@@ -1825,6 +1825,28 @@ int devm_cxl_enumerate_ports(struct cxl_memdev *cxlmd)if (is_cxl_host_bridge (dport_dev))return 0 ; +/* +* Check the downstream port's PM init status, and if it has +* failed retry PM init according to CXL Spec. 4.0 Sect. 8.1.5.1 +* - Implementation Note +*/ +if (dev_is_pci (dport_dev) &&dev_is_pci (iter->parent)) { +struct pci_dev *dport_pdev =to_pci_dev (dport_dev); + +if (!cxl_port_pm_init_is_complete (dport_pdev)) { +dev_dbg (&cxlmd->dev, +"PM init failed for %s, retrying PM init\n" , +dev_name (dport_dev)); + +cxl_reset_bus_function (to_pci_dev (iter->parent), false); + +if (!cxl_port_pm_init_is_complete (dport_pdev)) +dev_dbg (&cxlmd->dev, +"PM init failed retry for %s\n" , +dev_name (dport_dev)); + } + } + uport_dev = dport_dev->parent;if (!uport_dev) { dev_warn(dev, "at %s no parent for dport: %s\n",
drivers/cxl/cxlpci.h +3 -0
@@ -114,4 +114,7 @@ static inline void devm_cxl_port_ras_setup(struct cxl_port *port)int cxl_pci_setup_regs (struct pci_dev *pdev,enum cxl_regloc_type type,struct cxl_register_map *map); + +bool cxl_port_pm_init_is_complete (struct pci_dev *pdev); +#endif /* __CXL_PCI_H__ */
drivers/pci/pci.c +2 -1
@@ -4974,7 +4974,7 @@ static void cxl_restore_acs_sv_bme(struct pci_dev *bridge, u16 saved_cmd,* Return: 0 on success, -ENOTTY if the reset cannot be issued, or an * errno from the reset path. */ -static int cxl_reset_bus_function (struct pci_dev *dev,bool probe) +int cxl_reset_bus_function (struct pci_dev *dev,bool probe) {struct pci_dev *bridge;u16 dvsec, reg, val;
@@ -5023,6 +5023,7 @@ static int cxl_reset_bus_function(struct pci_dev *dev, bool probe)pci_dev_reset_iommu_done (dev);return rc; } +EXPORT_SYMBOL_NS_GPL (cxl_reset_bus_function,"CXL" );void pci_dev_lock (struct pci_dev *dev) {
include/linux/pci.h +1 -0
@@ -1477,6 +1477,7 @@ int pci_probe_reset_slot(struct pci_slot *slot);int pci_probe_reset_bus (struct pci_bus *bus);int pci_reset_bus (struct pci_dev *dev);void pci_reset_secondary_bus (struct pci_dev *dev); +int cxl_reset_bus_function (struct pci_dev *dev,bool probe);void pcibios_reset_secondary_bus (struct pci_dev *dev);void pci_update_resource (struct pci_dev *dev,int resno);int __must_check pci_assign_resource (struct pci_dev *dev,int i);
include/uapi/linux/pci_regs.h +2 -0
@@ -1369,6 +1369,8 @@/* CXL r4.0, 8.1.5: Extensions DVSEC for Ports */ #define PCI_DVSEC_CXL_PORT 3 +#define PCI_DVSEC_CXL_PORT_EXT_STATUS 0x0A +#define PCI_DVSEC_CXL_PORT_EXT_STATUS_PM_INIT_COMP _BITUL(0)#define PCI_DVSEC_CXL_PORT_CTL 0x0c#define PCI_DVSEC_CXL_PORT_CTL_UNMASK_SBR 0x00000001
Signature · 1 line
2.53.0
Dave Jiang
maintainerRe: [PATCH 2/2] cxl/core: Recover from PM Init failure via cxl_reset_bus_function()
Quoted 76 lines · Fabio M. De Francesco
CXL r4.0 sec 8.1.5.1 Implementation Note describes a scenario in which a Secondary Bus Reset, a Link Down, or Downstream Port Containment on a CXL Downstream Port prevents Port PM Init from completing when ACS Source Validation is enabled.
During CXL enumeration, for each CXL Downstream Port in a memdev's ancestry, check whether PM Init has completed. If it has not, invoke
cxl_reset_bus_function()which is exported for use by CXL.Signed-off-by Fabio M. De Francesco <[email protected]>--- drivers/cxl/core/pci.c | 30 ++++++++++++++++++++++++++++++ drivers/cxl/core/port.c | 22 ++++++++++++++++++++++ drivers/cxl/cxlpci.h | 3 +++ drivers/pci/pci.c | 3 ++- include/linux/pci.h | 1 + include/uapi/linux/pci_regs.h | 2 ++ 6 files changed, 60 insertions(+), 1 deletion(-)drivers/cxl/core/pci.c +30
-0@@ -926,3 +926,33 @@ int cxl_port_get_possible_dports(struct cxl_port *port)return ctx.count; } + +/** +* cxl_port_pm_init_is_complete - check the downstream port's PM Init Complete +* @pdev: downstream port +* +* Read the Port Power Management Initialization Complete bit in the +* Downstream Port's CXL DVSEC Port Extended Status register. +* +* Return: false only when the bit is observably clear. Return true when PM +* init is complete, when @pdev is not a CXL port (no Port DVSEC), or when +* the status register cannot be read. +*/ +bool cxl_port_pm_init_is_complete (struct pci_dev *pdev) +{ +u16 status; +u16 dvsec; +int rc; + + dvsec =pci_find_dvsec_capability (pdev,PCI_VENDOR_ID_CXL , +PCI_DVSEC_CXL_PORT ); +if (!dvsec) +return true; + + rc =pci_read_config_word (pdev, dvsec +PCI_DVSEC_CXL_PORT_EXT_STATUS , + &status); +if (rc ||PCI_POSSIBLE_ERROR (status)) +return true; + +return !!FIELD_GET (PCI_DVSEC_CXL_PORT_EXT_STATUS_PM_INIT_COMP , status); +}drivers/cxl/core/port.c +11
-0@@ -1825,6 +1825,28 @@ int devm_cxl_enumerate_ports(struct cxl_memdev *cxlmd)if (is_cxl_host_bridge (dport_dev))return 0 ; +/* +* Check the downstream port's PM init status, and if it has +* failed retry PM init according to CXL Spec. 4.0 Sect. 8.1.5.1 +* - Implementation Note +*/ +if (dev_is_pci (dport_dev) &&dev_is_pci (iter->parent)) { +struct pci_dev *dport_pdev =to_pci_dev (dport_dev); + +if (!cxl_port_pm_init_is_complete (dport_pdev)) { + dev_dbg(&cxlmd->dev, + "PM init failed for %s, retrying PM init\n",
drivers/cxl/core/port.c int devm_cxl_enumerate_ports(struct cxl_memdev *cxlmd) · line 1848
Quoted 10 lines
drivers/cxl/core/port.c +10
-0+ dev_name(dport_dev)); + +cxl_reset_bus_function (to_pci_dev (iter->parent), false); + +if (!cxl_port_pm_init_is_complete (dport_pdev)) +dev_dbg (&cxlmd->dev, +"PM init failed retry for %s\n" , +dev_name (dport_dev)); + } + }
Make this a helper function and move it to core/pci.c. Also pass 'struct device' and not 'struct pci_dev' to that function.
I do wonder if you reset it here, maybe you need to restart enumeration from the endpoint instead of just continuing as if nothing happened.
DJ
Quoted 62 lines
drivers/cxl/core/port.c +1
-0+ uport_dev = dport_dev->parent;if (!uport_dev) { dev_warn(dev, "at %s no parent for dport: %s\n",drivers/cxl/cxlpci.h +3
-0@@ -114,4 +114,7 @@ static inline void devm_cxl_port_ras_setup(struct cxl_port *port)int cxl_pci_setup_regs (struct pci_dev *pdev,enum cxl_regloc_type type,struct cxl_register_map *map); + +bool cxl_port_pm_init_is_complete (struct pci_dev *pdev); +#endif /* __CXL_PCI_H__ */ drivers/pci/pci.c +2
-1@@ -4974,7 +4974,7 @@ static void cxl_restore_acs_sv_bme(struct pci_dev *bridge, u16 saved_cmd,* Return: 0 on success, -ENOTTY if the reset cannot be issued, or an * errno from the reset path. */ -static int cxl_reset_bus_function (struct pci_dev *dev,bool probe) +int cxl_reset_bus_function (struct pci_dev *dev,bool probe) {struct pci_dev *bridge;u16 dvsec, reg, val;@@ -5023,6 +5023,7 @@ static int cxl_reset_bus_function(struct pci_dev *dev, bool probe)pci_dev_reset_iommu_done (dev);return rc; } +EXPORT_SYMBOL_NS_GPL (cxl_reset_bus_function,"CXL" );void pci_dev_lock (struct pci_dev *dev) {include/linux/pci.h +1
-0@@ -1477,6 +1477,7 @@ int pci_probe_reset_slot(struct pci_slot *slot);int pci_probe_reset_bus (struct pci_bus *bus);int pci_reset_bus (struct pci_dev *dev);void pci_reset_secondary_bus (struct pci_dev *dev); +int cxl_reset_bus_function (struct pci_dev *dev,bool probe);void pcibios_reset_secondary_bus (struct pci_dev *dev);void pci_update_resource (struct pci_dev *dev,int resno);int __must_check pci_assign_resource (struct pci_dev *dev,int i);include/uapi/linux/pci_regs.h +2
-0@@ -1369,6 +1369,8 @@/* CXL r4.0, 8.1.5: Extensions DVSEC for Ports */ #define PCI_DVSEC_CXL_PORT 3 +#define PCI_DVSEC_CXL_PORT_EXT_STATUS 0x0A +#define PCI_DVSEC_CXL_PORT_EXT_STATUS_PM_INIT_COMP _BITUL(0)#define PCI_DVSEC_CXL_PORT_CTL 0x0c#define PCI_DVSEC_CXL_PORT_CTL_UNMASK_SBR 0x00000001
Alison Schofield
maintainerRe: [PATCH 2/2] cxl/core: Recover from PM Init failure via cxl_reset_bus_function()
In reply to Fabio M. De FrancescoQuoted 8 lines · Fabio M. De Francesco
CXL r4.0 sec 8.1.5.1 Implementation Note describes a scenario in which a Secondary Bus Reset, a Link Down, or Downstream Port Containment on a CXL Downstream Port prevents Port PM Init from completing when ACS Source Validation is enabled.
During CXL enumeration, for each CXL Downstream Port in a memdev's ancestry, check whether PM Init has completed. If it has not, invoke
cxl_reset_bus_function()which is exported for use by CXL.
Hi Fabio, Not a full review yet, but that !! caught my eye, so...
Quoted 39 lines
Signed-off-by Fabio M. De Francesco <[email protected]>--- drivers/cxl/core/pci.c | 30 ++++++++++++++++++++++++++++++ drivers/cxl/core/port.c | 22 ++++++++++++++++++++++ drivers/cxl/cxlpci.h | 3 +++ drivers/pci/pci.c | 3 ++- include/linux/pci.h | 1 + include/uapi/linux/pci_regs.h | 2 ++ 6 files changed, 60 insertions(+), 1 deletion(-)drivers/cxl/core/pci.c +20
-0@@ -926,3 +926,33 @@ int cxl_port_get_possible_dports(struct cxl_port *port)return ctx.count; } + +/** +* cxl_port_pm_init_is_complete - check the downstream port's PM Init Complete +* @pdev: downstream port +* +* Read the Port Power Management Initialization Complete bit in the +* Downstream Port's CXL DVSEC Port Extended Status register. +* +* Return: false only when the bit is observably clear. Return true when PM +* init is complete, when @pdev is not a CXL port (no Port DVSEC), or when +* the status register cannot be read. +*/ +bool cxl_port_pm_init_is_complete (struct pci_dev *pdev) +{ +u16 status; +u16 dvsec; +int rc; + + dvsec =pci_find_dvsec_capability (pdev,PCI_VENDOR_ID_CXL , +PCI_DVSEC_CXL_PORT );
drivers/cxl/core/pci.c int cxl_port_get_possible_dports(struct cxl_port *port) · line 958
Quoted 10 lines
drivers/cxl/core/pci.c +10
-0+if (!dvsec) +return true; + + rc =pci_read_config_word (pdev, dvsec +PCI_DVSEC_CXL_PORT_EXT_STATUS , + &status); +if (rc ||PCI_POSSIBLE_ERROR (status)) +return true; + +return !!FIELD_GET (PCI_DVSEC_CXL_PORT_EXT_STATUS_PM_INIT_COMP , status); +}
The !! seems unnecessary here since this is already a single bit FIELD_GET(), ie. result is 0 or 1.
I also wouldn't mind this being extra reader friendly like below, but I'm happy if you just get rid of the !!
bool complete;
complete = FIELD_GET(....);
return complete;
Dave Jiang
maintainerQuoted 4 lines · Fabio M. De Francesco
Subject: [PATCH 0/2] PCI/CXL: Recover CXL Downstream Ports from PM Init failure
CXL r4.0 sec 8.1.5.1 Implementation Note describes a scenario in which a Secondary Bus Reset, a Link Down, or Downstream Port Containment on a
I'm not sure if this series covers a Link Down event (i.e. hotplug). As I recall, cxl_reset_bus_function() only happens via sysfs trigger.
DJ
Quoted 34 lines
CXL Downstream Port prevents Port PM Init from completing when ACS Source Validation is enabled on the Downstream Port. The spec states that another SBR alone does not recover the port and describes a software recovery sequence.
Patch 1 extends
cxl_reset_bus_function(), the helper backing thecxl_busPCI/CXL reset method exposed to userspace via sysfs. It saves, clears, and restores ACS Source Validation and Bus Master Enable on the CXL Downstream Port around the SBR it issues. This keeps the userspacecxl_busreset path from leaving the port unable to complete PM Init.Patch 2 adds a recovery pass during CXL enumeration. For each CXL Downstream Port in a memdev's ancestry, the CXL core checks whether PM Init has completed. If it has not, regardless of what caused the failure, it invokes
cxl_reset_bus_function()on the child below the port in the hope of restoring the port to a usable state. CXL enumeration re-runs after events that tear down and re-probe the memdev, including DPC, AER, and Link Down, so those paths reach this recovery.This small series is developed from an old RFC v3:
https://lore.kernel.org/linux-cxl/[email protected]/Fabio M. De Francesco (2):
PCI/CXL: Allow PM Init to complete oncxl_busreset if ACS SV enabled cxl/core: Recover from PM Init failure viacxl_reset_bus_function()
drivers/cxl/core/pci.c| 30 ++++++++++++++++++++drivers/cxl/core/port.c | 22 +++++++++++++++ drivers/cxl/cxlpci.h | 3 ++ drivers/pci/pci.c | 52 ++++++++++++++++++++++++++++++++++- include/linux/pci.h | 1 + include/uapi/linux/pci_regs.h | 2 ++ 6 files changed, 109 insertions(+), 1 deletion(-)
Re: [PATCH 0/2] PCI/CXL: Recover CXL Downstream Ports from PM Init failure
In reply to Fabio M. De FrancescoQuoted 31 lines · Fabio M. De Francesco
Subject: [PATCH 0/2] PCI/CXL: Recover CXL Downstream Ports from PM Init failure
CXL r4.0 sec 8.1.5.1 Implementation Note describes a scenario in which a Secondary Bus Reset, a Link Down, or Downstream Port Containment on a CXL Downstream Port prevents Port PM Init from completing when ACS Source Validation is enabled on the Downstream Port. The spec states that another SBR alone does not recover the port and describes a software recovery sequence.
Patch 1 extends
cxl_reset_bus_function(), the helper backing thecxl_busPCI/CXL reset method exposed to userspace via sysfs. It saves, clears, and restores ACS Source Validation and Bus Master Enable on the CXL Downstream Port around the SBR it issues. This keeps the userspacecxl_busreset path from leaving the port unable to complete PM Init.Patch 2 adds a recovery pass during CXL enumeration. For each CXL Downstream Port in a memdev's ancestry, the CXL core checks whether PM Init has completed. If it has not, regardless of what caused the failure, it invokes
cxl_reset_bus_function()on the child below the port in the hope of restoring the port to a usable state. CXL enumeration re-runs after events that tear down and re-probe the memdev, including DPC, AER, and Link Down, so those paths reach this recovery.This small series is developed from an old RFC v3:
https://lore.kernel.org/linux-cxl/[email protected]/Fabio M. De Francesco (2):
PCI/CXL: Allow PM Init to complete oncxl_busreset if ACS SV enabled cxl/core: Recover from PM Init failure viacxl_reset_bus_function()
Quoted 7 lines
drivers/cxl/core/pci.c | 30 ++++++++++++++++++++ drivers/cxl/core/port.c | 22 +++++++++++++++ drivers/cxl/cxlpci.h | 3 ++
drivers/pci/pci.c | 52 ++++++++++++++++++++++++++++++++++- include/linux/pci.h | 1 +include/uapi/linux/pci_regs.h| 2 ++6 files changed, 109 insertions(+), 1 deletion(-)
v2 of this series is under active development but its design has been heavily reworked wrt v1. All comments that are still relevant to the new version have been taken into consideration.
Thanks,
Fabio