[PATCH v4 18/24] EDAC/amd64: Define function to insert CS ID into address

From: Yazen Ghannam
Date: Thu Jan 27 2022 - 15:42:32 EST


Move the code that inserts the CS ID into the address into a separate
helper function.

Save the function pointer in the context struct. It will be set based on
interleaving mode rather than Data Fabric version. This will be expanded
for new interleaving modes added in future Data Fabric versions.

Signed-off-by: Yazen Ghannam <yazen.ghannam@xxxxxxx>
---
Link:
https://lore.kernel.org/r/20211028175728.121452-24-yazen.ghannam@xxxxxxx

v3->v4:
* No change.

v2->v3:
* Was patch 24 in v2.

v1->v2:
* Moved from arch/x86 to EDAC.
* Added function pointer to ctx struct.

drivers/edac/amd64_edac.c | 24 ++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index b2bcd8ea1a06..e3db4e98fe58 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -1083,6 +1083,7 @@ struct addr_ctx {
u8 cs_id;
int (*dehash_addr)(struct addr_ctx *ctx);
void (*make_space_for_cs_id)(struct addr_ctx *ctx);
+ void (*insert_cs_id)(struct addr_ctx *ctx);
};

struct data_fabric_ops {
@@ -1115,6 +1116,11 @@ static void make_space_for_cs_id_simple(struct addr_ctx *ctx)
expand_bits(ctx->intlv_addr_bit, num_intlv_bits, &ctx->ret_addr);
}

+static void insert_cs_id_simple(struct addr_ctx *ctx)
+{
+ ctx->ret_addr |= (ctx->cs_id << ctx->intlv_addr_bit);
+}
+
static u64 get_hi_addr_offset_df2(struct addr_ctx *ctx)
{
return (ctx->reg_dram_offset & GENMASK_ULL(31, 20)) << 8;
@@ -1146,6 +1152,7 @@ static int get_intlv_mode_df2(struct addr_ctx *ctx)
}

ctx->make_space_for_cs_id = make_space_for_cs_id_simple;
+ ctx->insert_cs_id = insert_cs_id_simple;

if (ctx->intlv_mode != NONE &&
ctx->intlv_mode != NOHASH_2CH &&
@@ -1306,8 +1313,6 @@ static int calculate_cs_id(struct addr_ctx *ctx)

static int denormalize_addr(struct addr_ctx *ctx)
{
- u8 num_intlv_bits;
-
/* Return early if no interleaving. */
if (ctx->intlv_mode == NONE)
return 0;
@@ -1326,20 +1331,7 @@ static int denormalize_addr(struct addr_ctx *ctx)
return -EINVAL;
}

- if (num_intlv_bits > 0) {
- u64 temp_addr_i;
-
- /*
- * The pre-interleaved address consists of XXXXXXIIIYYYYY
- * where III is the ID for this CS, and XXXXXXYYYYY are the
- * address bits from the post-interleaved address.
- * "num_intlv_bits" has been calculated to tell us how many "I"
- * bits there are. "intlv_addr_bit" tells us how many "Y" bits
- * there are (where "I" starts).
- */
- temp_addr_i = (ctx->cs_id << ctx->intlv_addr_bit);
- ctx->ret_addr |= temp_addr_i;
- }
+ ctx->insert_cs_id(ctx);

return 0;
}
--
2.25.1