cxl: Add endpoint decoder flags clear when PCI reset happens
Dave Jiang
maintainerPATCH 1/1 cxl: Add endpoint decoder flags clear when PCI reset happens
When a PCI reset happens, the lock and enable flags of the CXL device should be cleared to avoid stale state flags after reset. Add flag clearing during cxl_reset_done() to clear the relevant endpoint decoder flags for all decoders of the endpoint device.
--- drivers/cxl/cxl.h | 1 + drivers/cxl/pci.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)
drivers/cxl/cxl.h +1 -0
@@ -333,6 +333,7 @@ int cxl_dport_map_rcd_linkcap(struct pci_dev *pdev, struct cxl_dport *dport);#define CXL_DECODER_F_LOCK BIT(4)#define CXL_DECODER_F_ENABLE BIT(5)#define CXL_DECODER_F_NORMALIZED_ADDRESSING BIT(6) +#define CXL_DECODER_F_CLEAR_MASK (CXL_DECODER_F_ENABLE | CXL_DECODER_F_LOCK)enum cxl_decoder_type {CXL_DECODER_DEVMEM =2 ,
drivers/cxl/pci.c +16 -0
@@ -1030,6 +1030,19 @@ static void cxl_error_resume(struct pci_dev *pdev) dev->driver ? "successful" : "failed"); } +static int cxl_decoder_clear_flags (struct device *dev,void *data) +{ +struct cxl_endpoint_decoder *cxled; + +if (!is_endpoint_decoder (dev)) +return 0 ; + + cxled =to_cxl_endpoint_decoder (dev); + cxled->cxld.flags &= ~CXL_DECODER_F_CLEAR_MASK ; + +return 0 ; +} +static void cxl_reset_done (struct pci_dev *pdev) {struct cxl_dev_state *cxlds =pci_get_drvdata (pdev);
@@ -1045,6 +1058,9 @@ static void cxl_reset_done(struct pci_dev *pdev)guard (device)(&cxlmd->dev);if (cxlmd->endpoint &&cxl_endpoint_decoder_reset_detected (cxlmd->endpoint)) { +device_for_each_child (&cxlmd->endpoint->dev,NULL , + cxl_decoder_clear_flags); +dev_crit (dev,"SBR happened without memory regions removal.\n" );dev_crit (dev,"System may be unstable if regions hosted system memory.\n" );add_taint (TAINT_USER ,LOCKDEP_STILL_OK );
base-commit: 11439c4635edd669ae435eec308f4ab8a0804808
Signature · 1 line
2.53.0
Quoted 4 lines · Dave Jiang
When a PCI reset happens, the lock and enable flags of the CXL device should be cleared to avoid stale state flags after reset. Add flag clearing during
cxl_reset_done()to clear the relevant endpoint decoder flags for all decoders of the endpoint device.
Some opinions in code below, but with or without any changes:
Quoted 13 lines
Reproted-by Dan Williams <[email protected]>Signed-off-by Dave Jiang <[email protected]>--- drivers/cxl/cxl.h | 1 + drivers/cxl/pci.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)drivers/cxl/cxl.h +0
-0
drivers/cxl/cxl.h int cxl_dport_map_rcd_linkcap(struct pci_dev *pdev, struct cxl_dport *dport); · line 336
Quoted 4 lines
drivers/cxl/cxl.h +1
-0@@ -333,6 +333,7 @@ int cxl_dport_map_rcd_linkcap(struct pci_dev *pdev, struct cxl_dport *dport);#define CXL_DECODER_F_LOCK BIT(4)#define CXL_DECODER_F_ENABLE BIT(5)#define CXL_DECODER_F_NORMALIZED_ADDRESSING BIT(6) +#define CXL_DECODER_F_CLEAR_MASK (CXL_DECODER_F_ENABLE | CXL_DECODER_F_LOCK)
Maybe the RESET_MASK to tie it to the reset context.
Quoted 13 lines
drivers/cxl/cxl.h +0
-0enum cxl_decoder_type {CXL_DECODER_DEVMEM =2 ,drivers/cxl/pci.c +2
-0@@ -1030,6 +1030,19 @@ static void cxl_error_resume(struct pci_dev *pdev) dev->driver ? "successful" : "failed"); } +static int cxl_decoder_clear_flags (struct device *dev,void *data) +{
drivers/cxl/pci.c static void cxl_error_resume(struct pci_dev *pdev) · line 1044
Quoted 10 lines
drivers/cxl/pci.c +10
-0+struct cxl_endpoint_decoder *cxled; + +if (!is_endpoint_decoder (dev)) +return 0 ; + + cxled =to_cxl_endpoint_decoder (dev); + cxled->cxld.flags &= ~CXL_DECODER_F_CLEAR_MASK ; + +return 0 ; +}
Above is close to being a reusable helper where data can be the bits to clear. Then the name cxl_decoder_clear_flags() makes more sense. If it's special only for reset, decoder_reset_flags makes more sense.
Quoted 20 lines
drivers/cxl/pci.c +4
-0+static void cxl_reset_done (struct pci_dev *pdev) {struct cxl_dev_state *cxlds =pci_get_drvdata (pdev);@@ -1045,6 +1058,9 @@ static void cxl_reset_done(struct pci_dev *pdev)guard (device)(&cxlmd->dev);if (cxlmd->endpoint &&cxl_endpoint_decoder_reset_detected (cxlmd->endpoint)) { +device_for_each_child (&cxlmd->endpoint->dev,NULL , + cxl_decoder_clear_flags); +dev_crit (dev,"SBR happened without memory regions removal.\n" );dev_crit (dev,"System may be unstable if regions hosted system memory.\n" );add_taint (TAINT_USER ,LOCKDEP_STILL_OK );base-commit:
11439c4635edd669ae435eec308f4ab8a0804808Signature · 1 line
2.53.0