@@ -134,21 +134,14 @@ static int to_interleave_granularity(u32 ctrl)
{
int val = FIELD_GET(CXL_HDM_DECODER0_CTRL_IG_MASK, ctrl);
- return 256 << val;
+ return cxl_to_interleave_granularity(val);
}
static int to_interleave_ways(u32 ctrl)
{
int val = FIELD_GET(CXL_HDM_DECODER0_CTRL_IW_MASK, ctrl);
- switch (val) {
- case 0 ... 4:
- return 1 << val;
- case 8 ... 10:
- return 3 << (val - 8);
- default:
- return 0;
- }
+ return cxl_to_interleave_ways(val);
}
static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld,
@@ -64,6 +64,23 @@ static inline int cxl_hdm_decoder_count(u32 cap_hdr)
return val ? val * 2 : 1;
}
+static inline int cxl_to_interleave_granularity(u16 ig)
+{
+ return 256 << ig;
+}
+
+static inline int cxl_to_interleave_ways(u8 eniw)
+{
+ switch (eniw) {
+ case 0 ... 4:
+ return 1 << eniw;
+ case 8 ... 10:
+ return 3 << (eniw - 8);
+ default:
+ return 0;
+ }
+}
+
/* CXL 2.0 8.2.8.1 Device Capabilities Array Register */
#define CXLDEV_CAP_ARRAY_OFFSET 0x0
#define CXLDEV_CAP_ARRAY_CAP_ID 0
Interleave granularity and ways have specification defined encodings. Extracting this functionality into the common header file allows other consumers to make use of it. Signed-off-by: Ben Widawsky <ben.widawsky@intel.com> --- drivers/cxl/core/hdm.c | 11 ++--------- drivers/cxl/cxl.h | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-)