diff mbox series

[v4,12/24] EDAC/amd64: Define function to get number of interleaved channels

Message ID 20220127204115.384161-13-yazen.ghannam@amd.com (mailing list archive)
State New, archived
Headers show
Series AMD MCA Address Translation Updates | expand

Commit Message

Yazen Ghannam Jan. 27, 2022, 8:41 p.m. UTC
Move number of interleaved channel calculation to a separate helper
function. Drop unused cases.

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

v3->v4:
* No change.

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

v1->v2:
* Moved from arch/x86 to EDAC.

 drivers/edac/amd64_edac.c | 42 +++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

Comments

Borislav Petkov Feb. 14, 2022, 12:20 p.m. UTC | #1
On Thu, Jan 27, 2022 at 08:41:03PM +0000, Yazen Ghannam wrote:
> Move number of interleaved channel calculation to a separate helper
> function. Drop unused cases.

... or by looking at that change, I think you want to have each separate
step in the address massaging be a separate function. Which, if so,
makes sense but you have to say it...

...

> +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. */

"were"

> +		break;
> +	}
> +}
Yazen Ghannam March 9, 2022, 10:13 p.m. UTC | #2
On Mon, Feb 14, 2022 at 01:20:44PM +0100, Borislav Petkov wrote:
> On Thu, Jan 27, 2022 at 08:41:03PM +0000, Yazen Ghannam wrote:
> > Move number of interleaved channel calculation to a separate helper
> > function. Drop unused cases.
> 
> ... or by looking at that change, I think you want to have each separate
> step in the address massaging be a separate function. Which, if so,
> makes sense but you have to say it...
>

Yep, will do.
 
> ...
> 
> > +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. */
> 
> "were"

Will fix.

Thanks,
Yazen
diff mbox series

Patch

diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index b75311acbe13..87439374a076 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -1076,6 +1076,7 @@  struct addr_ctx {
 	u8 inst_id;
 	u8 map_num;
 	u8 intlv_addr_bit;
+	u8 intlv_num_chan;
 	u8 cs_id;
 	int (*dehash_addr)(struct addr_ctx *ctx);
 };
@@ -1197,10 +1198,27 @@  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)
 {
 	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. */
@@ -1213,23 +1231,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",
@@ -1266,8 +1270,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;
 		}