[PATCH 14/25] x86/MCE/AMD: Define function to get number of interleaved channels
From: Yazen Ghannam
Date: Fri May 07 2021 - 15:02:49 EST
From: Yazen Ghannam <yazen.ghannam@xxxxxxx>
Move number of interleaved channel calculation to a separate helper
function. Drop unused cases.
Signed-off-by: Yazen Ghannam <yazen.ghannam@xxxxxxx>
---
arch/x86/kernel/cpu/mce/amd.c | 42 +++++++++++++++++++----------------
1 file changed, 23 insertions(+), 19 deletions(-)
diff --git a/arch/x86/kernel/cpu/mce/amd.c b/arch/x86/kernel/cpu/mce/amd.c
index 605376351cc8..0c24bdc346a3 100644
--- a/arch/x86/kernel/cpu/mce/amd.c
+++ b/arch/x86/kernel/cpu/mce/amd.c
@@ -729,6 +729,7 @@ struct addr_ctx {
u8 umc;
u8 map_num;
u8 intlv_addr_bit;
+ u8 intlv_num_chan;
u8 cs_id;
bool hash_enabled;
};
@@ -830,12 +831,29 @@ static int get_intlv_addr_bit(struct addr_ctx *ctx)
return 0;
}
+static void get_intlv_num_chan(struct addr_ctx *ctx)
+{
+ /* Save the log2(# of channels). */
+ switch (ctx->intlv_mode) {
+ case NONE:
+ ctx->intlv_num_chan = 0;
+ break;
+ case NOHASH_2CH:
+ case DF2_HASH_2CH:
+ ctx->intlv_num_chan = 1;
+ break;
+ default:
+ /* Valid interleaving modes where checked earlier. */
+ break;
+ }
+}
+
static int denormalize_addr(struct addr_ctx *ctx)
{
u32 tmp;
u8 die_id_shift, die_id_mask, socket_id_shift, socket_id_mask;
- u8 intlv_num_dies, intlv_num_chan, intlv_num_sockets;
+ u8 intlv_num_dies, intlv_num_sockets;
u8 num_intlv_bits, cs_mask = 0;
/* Return early if no interleaving. */
@@ -848,23 +866,9 @@ static int denormalize_addr(struct addr_ctx *ctx)
intlv_num_sockets = (ctx->reg_limit_addr >> 8) & 0x1;
intlv_num_dies = (ctx->reg_limit_addr >> 10) & 0x3;
- /* Re-use intlv_num_chan by setting it equal to log2(#channels) */
- switch (intlv_num_chan) {
- case 0: intlv_num_chan = 0; break;
- case 1: intlv_num_chan = 1; break;
- case 3: intlv_num_chan = 2; break;
- case 5: intlv_num_chan = 3; break;
- case 7: intlv_num_chan = 4; break;
-
- case 8: intlv_num_chan = 1;
- break;
- default:
- pr_err("%s: Invalid number of interleaved channels %d.\n",
- __func__, intlv_num_chan);
- return -EINVAL;
- }
+ get_intlv_num_chan(ctx);
- num_intlv_bits = intlv_num_chan;
+ num_intlv_bits = ctx->intlv_num_chan;
if (intlv_num_dies > 2) {
pr_err("%s: Invalid number of interleaved nodes/dies %d.\n",
@@ -901,8 +905,8 @@ static int denormalize_addr(struct addr_ctx *ctx)
die_id_bit = 0;
/* If interleaved over more than 1 channel: */
- if (intlv_num_chan) {
- die_id_bit = intlv_num_chan;
+ if (ctx->intlv_num_chan) {
+ die_id_bit = ctx->intlv_num_chan;
cs_mask = (1 << die_id_bit) - 1;
ctx->cs_id = cs_fabric_id & cs_mask;
}
--
2.25.1