Skip to contentSkip to conversation

cxl/hdm: Fix decoder count calculation

PATCH Superseded Ben Widawsky 3 participants 5 messages Jun 10, 2021 – Jun 11, 2021 CXL

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cxl/hdm: Fix decoder count calculation

The decoder count in the HDM decoder capability structure is an encoded field. As defined in the spec:

Decoder Count: Reports the number of memory address decoders implemented by the component.
0 – 1 Decoder
1 – 2 Decoders
2 – 4 Decoders
3 – 6 Decoders
4 – 8 Decoders
5 – 10 DecodersAll other values are reserved

Nothing is actually fixed by this as nothing actually used this mapping yet.

Cc Jonathan Cameron <[email protected]>
Cc Ira Weiny <[email protected]>
---
 drivers/cxl/core.c | 3 ++-
 drivers/cxl/cxl.h  | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/cxl/core.c +2 -1
index cda09a9cd98e..92db02fe7aa8 100644
@@ -666,7 +666,8 @@ void cxl_probe_component_regs(struct device *dev, void __iomem *base,
 
 			hdr = readl(register_block);
 
-			decoder_cnt = FIELD_GET(CXL_HDM_DECODER_COUNT_MASK, hdr);
+			decoder_cnt =
+				cxl_hdm_decoder_count(FIELD_GET(CXL_HDM_DECODER_COUNT_MASK, hdr));
 			length = 0x20 * decoder_cnt + 0x10;
 
 			map->hdm_decoder.valid = true;
drivers/cxl/cxl.h +1 -0
index 1ffc5e07e24d..f0dff7d96286 100644
@@ -35,6 +35,7 @@
 /* HDM decoders CXL 2.0 8.2.5.12 CXL HDM Decoder Capability Structure */
 #define CXL_HDM_DECODER_CAP_OFFSET 0x0
 #define   CXL_HDM_DECODER_COUNT_MASK GENMASK(3, 0)
+#define	    cxl_hdm_decoder_count(bits) ((bits) == 0 ? 1 : (bits) * 2)
 #define   CXL_HDM_DECODER_TARGET_COUNT_MASK GENMASK(7, 4)
 #define CXL_HDM_DECODER0_BASE_LOW_OFFSET 0x10
 #define CXL_HDM_DECODER0_BASE_HIGH_OFFSET 0x14
Signature · 1 line
2.32.0
#1 lore raw
Quoted 29 lines · Ben Widawsky

The decoder count in the HDM decoder capability structure is an encoded field. As defined in the spec:

Decoder Count: Reports the number of memory address decoders implemented by the component.
0 – 1 Decoder
1 – 2 Decoders
2 – 4 Decoders
3 – 6 Decoders
4 – 8 Decoders
5 – 10 DecodersAll other values are reserved

Nothing is actually fixed by this as nothing actually used this mapping yet.

Cc Jonathan Cameron <[email protected]>
Cc Ira Weiny <[email protected]>
---
 drivers/cxl/core.c | 3 ++-
 drivers/cxl/cxl.h  | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/cxl/core.c +0 -0
index cda09a9cd98e..92db02fe7aa8 100644

drivers/cxl/core.c void cxl_probe_component_regs(struct device *dev, void __iomem *base, · line 670

Quoted 6 lines
drivers/cxl/core.c +2 -1
@@ -666,7 +666,8 @@ void cxl_probe_component_regs(struct device *dev, void __iomem *base,
 
                        hdr = readl(register_block);
 
-                       decoder_cnt = FIELD_GET(CXL_HDM_DECODER_COUNT_MASK, hdr);
+                       decoder_cnt =
+                               cxl_hdm_decoder_count(FIELD_GET(CXL_HDM_DECODER_COUNT_MASK, hdr));

How about make it a static inline helper that takes @hdr and move the FIELD_GET inside there to save some indentation?

I still think it warrants a Fixes: tag, the commit ids in cxl.git/next are stable.

Acked-by on v1 1/1
#2 lore raw
In reply to Ben Widawsky
Quoted 12 lines · On Thu, 10 Jun 2021 14:53:32 -0700 Ben Widawsky <[email protected]> wrote:

The decoder count in the HDM decoder capability structure is an encoded field. As defined in the spec:

Decoder Count: Reports the number of memory address decoders implemented by the component.
0 – 1 Decoder
1 – 2 Decoders
2 – 4 Decoders
3 – 6 Decoders
4 – 8 Decoders
5 – 10 DecodersAll other values are reserved

Quoted 6 lines

Nothing is actually fixed by this as nothing actually used this mapping yet.

Cc Jonathan Cameron <[email protected]>
Cc Ira Weiny <[email protected]>

lgtm.

Quoted 31 lines
---
 drivers/cxl/core.c | 3 ++-
 drivers/cxl/cxl.h  | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/cxl/core.c +2 -1
index cda09a9cd98e..92db02fe7aa8 100644
@@ -666,7 +666,8 @@ void cxl_probe_component_regs(struct device *dev, void __iomem *base,
 
 			hdr = readl(register_block);
 
-			decoder_cnt = FIELD_GET(CXL_HDM_DECODER_COUNT_MASK, hdr);
+			decoder_cnt =
+				cxl_hdm_decoder_count(FIELD_GET(CXL_HDM_DECODER_COUNT_MASK, hdr));
 			length = 0x20 * decoder_cnt + 0x10;
 
 			map->hdm_decoder.valid = true;
drivers/cxl/cxl.h +1 -0
index 1ffc5e07e24d..f0dff7d96286 100644
@@ -35,6 +35,7 @@
 /* HDM decoders CXL 2.0 8.2.5.12 CXL HDM Decoder Capability Structure */
 #define CXL_HDM_DECODER_CAP_OFFSET 0x0
 #define   CXL_HDM_DECODER_COUNT_MASK GENMASK(3, 0)
+#define	    cxl_hdm_decoder_count(bits) ((bits) == 0 ? 1 : (bits) * 2)
 #define   CXL_HDM_DECODER_TARGET_COUNT_MASK GENMASK(7, 4)
 #define CXL_HDM_DECODER0_BASE_LOW_OFFSET 0x10
 #define CXL_HDM_DECODER0_BASE_HIGH_OFFSET 0x14
#3 lore raw

PATCH v2 1/1 cxl/hdm: Fix decoder count calculation

In reply to Ben Widawsky

The decoder count in the HDM decoder capability structure is an encoded field. As defined in the spec:

Decoder Count: Reports the number of memory address decoders implemented by the component.
0 – 1 Decoder
1 – 2 Decoders
2 – 4 Decoders
3 – 6 Decoders
4 – 8 Decoders
5 – 10 Decoders
All other values are reserved

Nothing is actually fixed by this as nothing actually used this mapping yet.

---
v2:
- Minor whitespace cleanup in commit message.
- Move value decoder to inline function. (Dan)
- Rework value decoding logic to be more concise.

---
 drivers/cxl/core.c | 2 +-
 drivers/cxl/cxl.h  | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/cxl/core.c +1 -1
index 6db660249cea..49744ad885de 100644
@@ -603,7 +603,7 @@ void cxl_probe_component_regs(struct device *dev, void __iomem *base,
 
 			hdr = readl(register_block);
 
-			decoder_cnt = FIELD_GET(CXL_HDM_DECODER_COUNT_MASK, hdr);
+			decoder_cnt = cxl_hdm_decoder_count(hdr);
 			length = 0x20 * decoder_cnt + 0x10;
 
 			map->hdm_decoder.valid = true;
drivers/cxl/cxl.h +7 -0
index 3f9a6f7b05db..f1e52487c644 100644
@@ -42,6 +42,13 @@
 #define CXL_HDM_DECODER0_SIZE_HIGH_OFFSET 0x1c
 #define CXL_HDM_DECODER0_CTRL_OFFSET 0x20
 
+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;
+}
+
 /* CXL 2.0 8.2.8.1 Device Capabilities Array Register */
 #define CXLDEV_CAP_ARRAY_OFFSET 0x0
 #define   CXLDEV_CAP_ARRAY_CAP_ID 0
Signature · 1 line
2.32.0
#4 lore raw
Quoted 14 lines · Ben Widawsky

The decoder count in the HDM decoder capability structure is an encoded field. As defined in the spec:

Decoder Count: Reports the number of memory address decoders implemented by the component.
0 – 1 Decoder
1 – 2 Decoders
2 – 4 Decoders
3 – 6 Decoders
4 – 8 Decoders
5 – 10 Decoders
All other values are reserved

Quoted 2 lines

Nothing is actually fixed by this as nothing actually used this mapping yet.

I'll still add the Fixes tag because the original commit is broken even if the impact of fixing this bug is moot in the near term.