Skip to contentSkip to conversation

cxl/hdm: Add support for 32 switch decoders

PATCH In review Li Ming 4 participants 6 messages Mar 21 – Apr 10 CXL

lore
Share & tools
lore

Li Ming

author reviewer
#0 lore raw

PATCH v2 1/1 cxl/hdm: Add support for 32 switch decoders

Per CXL r4.0 section 8.2.4.20.1. CXL host bridge and switch ports can support 32 HDM decoders. Current implementation misses some decoders on CXL host bridge and switch in the case that the value of Decoder Count field in CXL HDM decoder Capability Register is greater than or equal to 9.

Update calculation implementation to ensure the decoder count calculation is correct for CXL host bridge/switch ports.

---
Changes from v1:
- Return -ENXIO if the value violates SPEC. (Dave & Alison)

---
 drivers/cxl/core/hdm.c |  2 +-
 drivers/cxl/cxl.h      | 11 ++++++++++-
 drivers/cxl/cxlmem.h   |  2 +-
 3 files changed, 12 insertions(+), 3 deletions(-)
drivers/cxl/core/hdm.c +1 -1
index c222e98ae736..3930e130d6b6 100644
@@ -177,7 +177,7 @@ static struct cxl_hdm *devm_cxl_setup_hdm(struct cxl_port *port,
 	}
 
 	parse_hdm_decoder_caps(cxlhdm);
-	if (cxlhdm->decoder_count == 0) {
+	if (cxlhdm->decoder_count < 0) {
 		dev_err(dev, "Spec violation. Caps invalid\n");
 		return ERR_PTR(-ENXIO);
 	}
drivers/cxl/cxl.h +10 -1
index 9b947286eb9b..0a5301049cf3 100644
@@ -77,7 +77,16 @@ static inline int cxl_hdm_decoder_count(u32 cap_hdr)
 {
 	int val = FIELD_GET(CXL_HDM_DECODER_COUNT_MASK, cap_hdr);
 
-	return val ? val * 2 : 1;
+	switch (val) {
+	case 0:
+		return 1;
+	case 1 ... 8:
+		return val * 2;
+	case 9 ... 12:
+		return (val - 4) * 4;
+	default:
+		return -ENXIO;
+	}
 }
 
 /* Encode defined in CXL 2.0 8.2.5.12.7 HDM Decoder Control Register */
drivers/cxl/cxlmem.h +1 -1
index e21d744d639b..399b150b404c 100644
@@ -923,7 +923,7 @@ int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd);
  */
 struct cxl_hdm {
 	struct cxl_component_regs regs;
-	unsigned int decoder_count;
+	int decoder_count;
 	unsigned int target_count;
 	unsigned int interleave_mask;
 	unsigned long iw_cap_mask;
Signature · 1 line
2.43.0
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Li Ming

Per CXL r4.0 section 8.2.4.20.1. CXL host bridge and switch ports can support 32 HDM decoders. Current implementation misses some decoders on CXL host bridge and switch in the case that the value of Decoder Count field in CXL HDM decoder Capability Register is greater than or equal to 9.

Update calculation implementation to ensure the decoder count calculation is correct for CXL host bridge/switch ports.

maintainer Reviewed-by on v2 1/1
#2 lore raw
In reply to Li Ming
Quoted 10 lines · Li Ming

Per CXL r4.0 section 8.2.4.20.1. CXL host bridge and switch ports can support 32 HDM decoders. Current implementation misses some decoders on CXL host bridge and switch in the case that the value of Decoder Count field in CXL HDM decoder Capability Register is greater than or equal to 9.

Update calculation implementation to ensure the decoder count calculation is correct for CXL host bridge/switch ports.

Quoted 57 lines

---
Changes from v1:
- Return -ENXIO if the value violates SPEC. (Dave & Alison)

---
 drivers/cxl/core/hdm.c |  2 +-
 drivers/cxl/cxl.h      | 11 ++++++++++-
 drivers/cxl/cxlmem.h   |  2 +-
 3 files changed, 12 insertions(+), 3 deletions(-)
drivers/cxl/core/hdm.c +1 -1
index c222e98ae736..3930e130d6b6 100644
@@ -177,7 +177,7 @@ static struct cxl_hdm *devm_cxl_setup_hdm(struct cxl_port *port,
 	}
 
 	parse_hdm_decoder_caps(cxlhdm);
-	if (cxlhdm->decoder_count == 0) {
+	if (cxlhdm->decoder_count < 0) {
 		dev_err(dev, "Spec violation. Caps invalid\n");
 		return ERR_PTR(-ENXIO);
 	}
drivers/cxl/cxl.h +10 -1
index 9b947286eb9b..0a5301049cf3 100644
@@ -77,7 +77,16 @@ static inline int cxl_hdm_decoder_count(u32 cap_hdr)
 {
 	int val = FIELD_GET(CXL_HDM_DECODER_COUNT_MASK, cap_hdr);
 
-	return val ? val * 2 : 1;
+	switch (val) {
+	case 0:
+		return 1;
+	case 1 ... 8:
+		return val * 2;
+	case 9 ... 12:
+		return (val - 4) * 4;
+	default:
+		return -ENXIO;
+	}
 }
 
 /* Encode defined in CXL 2.0 8.2.5.12.7 HDM Decoder Control Register */
drivers/cxl/cxlmem.h +1 -1
index e21d744d639b..399b150b404c 100644
@@ -923,7 +923,7 @@ int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd);
  */
 struct cxl_hdm {
 	struct cxl_component_regs regs;
-	unsigned int decoder_count;
+	int decoder_count;
 	unsigned int target_count;
 	unsigned int interleave_mask;
 	unsigned long iw_cap_mask;
Reviewed-by on v2 1/1
#3 lore raw
In reply to Li Ming
Quoted 10 lines · Li Ming

Per CXL r4.0 section 8.2.4.20.1. CXL host bridge and switch ports can support 32 HDM decoders. Current implementation misses some decoders on CXL host bridge and switch in the case that the value of Decoder Count field in CXL HDM decoder Capability Register is greater than or equal to 9.

Update calculation implementation to ensure the decoder count calculation is correct for CXL host bridge/switch ports.

author reviewer
#4 lore raw
In reply to Li Ming

kindly ping.

Is this patch missing in cxl/next?

Ming

Quoted 67 lines · Li Ming

Per CXL r4.0 section 8.2.4.20.1. CXL host bridge and switch ports can support 32 HDM decoders. Current implementation misses some decoders on CXL host bridge and switch in the case that the value of Decoder Count field in CXL HDM decoder Capability Register is greater than or equal to 9.

Update calculation implementation to ensure the decoder count calculation is correct for CXL host bridge/switch ports.

---
Changes from v1:
- Return -ENXIO if the value violates SPEC. (Dave & Alison)

---
  drivers/cxl/core/hdm.c |  2 +-
  drivers/cxl/cxl.h      | 11 ++++++++++-
  drivers/cxl/cxlmem.h   |  2 +-
  3 files changed, 12 insertions(+), 3 deletions(-)
drivers/cxl/core/hdm.c +1 -1
index c222e98ae736..3930e130d6b6 100644
@@ -177,7 +177,7 @@ static struct cxl_hdm *devm_cxl_setup_hdm(struct cxl_port *port,
  	}
 
  	parse_hdm_decoder_caps(cxlhdm);
-	if (cxlhdm->decoder_count == 0) {
+	if (cxlhdm->decoder_count < 0) {
  		dev_err(dev, "Spec violation. Caps invalid\n");
  		return ERR_PTR(-ENXIO);
  	}
drivers/cxl/cxl.h +10 -1
index 9b947286eb9b..0a5301049cf3 100644
@@ -77,7 +77,16 @@ static inline int cxl_hdm_decoder_count(u32 cap_hdr)
  {
  	int val = FIELD_GET(CXL_HDM_DECODER_COUNT_MASK, cap_hdr);
 
-	return val ? val * 2 : 1;
+	switch (val) {
+	case 0:
+		return 1;
+	case 1 ... 8:
+		return val * 2;
+	case 9 ... 12:
+		return (val - 4) * 4;
+	default:
+		return -ENXIO;
+	}
  }
 
  /* Encode defined in CXL 2.0 8.2.5.12.7 HDM Decoder Control Register */
drivers/cxl/cxlmem.h +1 -1
index e21d744d639b..399b150b404c 100644
@@ -923,7 +923,7 @@ int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd);
   */
  struct cxl_hdm {
  	struct cxl_component_regs regs;
-	unsigned int decoder_count;
+	int decoder_count;
  	unsigned int target_count;
  	unsigned int interleave_mask;
  	unsigned long iw_cap_mask;
maintainer
#5 lore raw
Quoted 3 lines · Li Ming

kindly ping.

Is this patch missing in cxl/next?

Sorry I missed it. Applied to cxl/next
3624a22783b7

Quoted 69 lines

Ming

Quoted 64 lines · Li Ming

Per CXL r4.0 section 8.2.4.20.1. CXL host bridge and switch ports can support 32 HDM decoders. Current implementation misses some decoders on CXL host bridge and switch in the case that the value of Decoder Count field in CXL HDM decoder Capability Register is greater than or equal to 9.

Update calculation implementation to ensure the decoder count calculation is correct for CXL host bridge/switch ports.

---
Changes from v1:
- Return -ENXIO if the value violates SPEC. (Dave & Alison)
---
  drivers/cxl/core/hdm.c |  2 +-
  drivers/cxl/cxl.h      | 11 ++++++++++- drivers/cxl/cxlmem.h   |  2 +-

  3 files changed, 12 insertions(+), 3 deletions(-)
drivers/cxl/core/hdm.c +1 -1
index c222e98ae736..3930e130d6b6 100644
@@ -177,7 +177,7 @@ static struct cxl_hdm *devm_cxl_setup_hdm(struct cxl_port *port,
       }
         parse_hdm_decoder_caps(cxlhdm);
-    if (cxlhdm->decoder_count == 0) {
+    if (cxlhdm->decoder_count < 0) {
           dev_err(dev, "Spec violation. Caps invalid\n");
           return ERR_PTR(-ENXIO);
       }
drivers/cxl/cxl.h +10 -0
index 9b947286eb9b..0a5301049cf3 100644
@@ -77,7 +77,16 @@ static inline int cxl_hdm_decoder_count(u32 cap_hdr)
   {
       int val = FIELD_GET(CXL_HDM_DECODER_COUNT_MASK, cap_hdr);
   -    return val ? val * 2 : 1;
+    switch (val) {
+    case 0:
+        return 1;
+    case 1 ... 8:
+        return val * 2;
+    case 9 ... 12:
+        return (val - 4) * 4;
+    default:
+        return -ENXIO;
+    }
   }
     /* Encode defined in CXL 2.0 8.2.5.12.7 HDM Decoder Control Register */
drivers/cxl/cxlmem.h +1 -1
index e21d744d639b..399b150b404c 100644
@@ -923,7 +923,7 @@ int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd);
    */
   struct cxl_hdm {
       struct cxl_component_regs regs;
-    unsigned int decoder_count;
+    int decoder_count;
       unsigned int target_count;
       unsigned int interleave_mask;
       unsigned long iw_cap_mask;