ac32bf
From 2d656c4ec9d5f68ac39b2a8461b0cd4f77dd7c21 Mon Sep 17 00:00:00 2001
ac32bf
From: Marcin Koss <marcin.koss@intel.com>
ac32bf
Date: Thu, 3 Dec 2015 15:19:47 +0100
ac32bf
Subject: [PATCH 3/5] rasdaemon: Add support for Knights Landing processor
ac32bf
ac32bf
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
ac32bf
---
ac32bf
 Makefile.am       |   3 +-
ac32bf
 mce-intel-knl.c   | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
ac32bf
 mce-intel.c       |   5 +++
ac32bf
 ras-mce-handler.c |   1 +
ac32bf
 ras-mce-handler.h |   1 +
ac32bf
 5 files changed, 137 insertions(+), 1 deletion(-)
ac32bf
 create mode 100644 mce-intel-knl.c
ac32bf
ac32bf
diff --git a/Makefile.am b/Makefile.am
ac32bf
index a6bf18f..a1cb02a 100644
ac32bf
--- a/Makefile.am
ac32bf
+++ b/Makefile.am
ac32bf
@@ -28,7 +28,8 @@ if WITH_MCE
ac32bf
    rasdaemon_SOURCES += ras-mce-handler.c mce-intel.c mce-amd-k8.c \
ac32bf
 			mce-intel-p4-p6.c mce-intel-nehalem.c \
ac32bf
 			mce-intel-dunnington.c mce-intel-tulsa.c \
ac32bf
-			mce-intel-sb.c mce-intel-ivb.c mce-intel-haswell.c
ac32bf
+			mce-intel-sb.c mce-intel-ivb.c mce-intel-haswell.c \
ac32bf
+			mce-intel-knl.c
ac32bf
 endif
ac32bf
 if WITH_EXTLOG
ac32bf
    rasdaemon_SOURCES += ras-extlog-handler.c
ac32bf
diff --git a/mce-intel-knl.c b/mce-intel-knl.c
ac32bf
new file mode 100644
ac32bf
index 0000000..96b0a59
ac32bf
--- /dev/null
ac32bf
+++ b/mce-intel-knl.c
ac32bf
@@ -0,0 +1,128 @@
ac32bf
+/*
ac32bf
+ * This program is free software; you can redistribute it and/or modify
ac32bf
+ * it under the terms of the GNU General Public License as published by
ac32bf
+ * the Free Software Foundation; either version 2 of the License, or
ac32bf
+ * (at your option) any later version.
ac32bf
+ *
ac32bf
+ * This program is distributed in the hope that it will be useful,
ac32bf
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
ac32bf
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ac32bf
+ * GNU General Public License for more details.
ac32bf
+ *
ac32bf
+ * You should have received a copy of the GNU General Public License
ac32bf
+ * along with this program; if not, write to the Free Software
ac32bf
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ac32bf
+*/
ac32bf
+
ac32bf
+#include <string.h>
ac32bf
+#include <stdio.h>
ac32bf
+
ac32bf
+#include "ras-mce-handler.h"
ac32bf
+#include "bitfield.h"
ac32bf
+
ac32bf
+static struct field memctrl_mc7[] = {
ac32bf
+	SBITFIELD(16, "CA Parity error"),
ac32bf
+	SBITFIELD(17, "Internal Parity error except WDB"),
ac32bf
+	SBITFIELD(18, "Internal Parity error from WDB"),
ac32bf
+	SBITFIELD(19, "Correctable Patrol Scrub"),
ac32bf
+	SBITFIELD(20, "Uncorrectable Patrol Scrub"),
ac32bf
+	SBITFIELD(21, "Spare Correctable Error"),
ac32bf
+	SBITFIELD(22, "Spare UC Error"),
ac32bf
+	SBITFIELD(23, "CORR Chip fail even MC only, 4 bit burst error EDC only"),
ac32bf
+	{}
ac32bf
+};
ac32bf
+
ac32bf
+void knl_decode_model(struct ras_events *ras, struct mce_event *e)
ac32bf
+{
ac32bf
+	uint64_t status = e->status;
ac32bf
+	uint32_t mca = status & 0xffff;
ac32bf
+	unsigned rank0 = -1, rank1 = -1, chan = 0;
ac32bf
+
ac32bf
+	switch (e->bank) {
ac32bf
+	case 5:
ac32bf
+		switch (EXTRACT(status, 0, 15)) {
ac32bf
+		case 0x402:
ac32bf
+			mce_snprintf(e->mcastatus_msg, "PCU Internal Errors");
ac32bf
+			break;
ac32bf
+		case 0x403:
ac32bf
+			mce_snprintf(e->mcastatus_msg, "VCU Internal Errors");
ac32bf
+			break;
ac32bf
+		case 0x407:
ac32bf
+			mce_snprintf(e->mcastatus_msg, "Other UBOX Internal Errors");
ac32bf
+			break;
ac32bf
+		}
ac32bf
+		break;
ac32bf
+	case 7: case 8: case 9: case 10:
ac32bf
+	case 11: case 12: case 13: case 14:
ac32bf
+	case 15: case 16:
ac32bf
+		if ((EXTRACT(status, 0, 15)) == 0x5) {
ac32bf
+			mce_snprintf(e->mcastatus_msg, "Internal Parity error");
ac32bf
+		} else {
ac32bf
+			chan = (EXTRACT(status, 0, 3)) + 3 * (e->bank == 15);
ac32bf
+			switch (EXTRACT(status, 4, 7)) {
ac32bf
+			case 0x0:
ac32bf
+				mce_snprintf(e->mcastatus_msg, "Undefined request on channel %d", chan);
ac32bf
+				break;
ac32bf
+			case 0x1:
ac32bf
+				mce_snprintf(e->mcastatus_msg, "Read on channel %d", chan);
ac32bf
+				break;
ac32bf
+			case 0x2:
ac32bf
+				mce_snprintf(e->mcastatus_msg, "Write on channel %d", chan);
ac32bf
+				break;
ac32bf
+			case 0x3:
ac32bf
+				mce_snprintf(e->mcastatus_msg, "CA error on channel %d", chan);
ac32bf
+				break;
ac32bf
+			case 0x4:
ac32bf
+				mce_snprintf(e->mcastatus_msg, "Scrub error on channel %d", chan);
ac32bf
+				break;
ac32bf
+			}
ac32bf
+		}
ac32bf
+		decode_bitfield(e, status, memctrl_mc7);
ac32bf
+		break;
ac32bf
+	default:
ac32bf
+		break;
ac32bf
+	}
ac32bf
+
ac32bf
+	/*
ac32bf
+	 * Memory error specific code. Returns if the error is not a MC one
ac32bf
+	 */
ac32bf
+
ac32bf
+	/* Check if the error is at the memory controller */
ac32bf
+	if ((mca >> 7) != 1)
ac32bf
+		return;
ac32bf
+
ac32bf
+	/* Ignore unless this is an corrected extended error from an iMC bank */
ac32bf
+	if (e->bank < 7 || e->bank > 16 || (status & MCI_STATUS_UC) ||
ac32bf
+		!test_prefix(7, status & 0xefff))
ac32bf
+		return;
ac32bf
+
ac32bf
+	/*
ac32bf
+	 * Parse the reported channel and ranks
ac32bf
+	 */
ac32bf
+
ac32bf
+	chan = EXTRACT(status, 0, 3);
ac32bf
+	if (chan == 0xf)
ac32bf
+	{
ac32bf
+		mce_snprintf(e->mc_location, "memory_channel=unspecified");
ac32bf
+	}
ac32bf
+	else
ac32bf
+	{
ac32bf
+		chan = chan + 3 * (e->bank == 15);
ac32bf
+		mce_snprintf(e->mc_location, "memory_channel=%d", chan);
ac32bf
+
ac32bf
+		if (EXTRACT(e->misc, 62, 62))
ac32bf
+			rank0 = EXTRACT(e->misc, 46, 50);
ac32bf
+		if (EXTRACT(e->misc, 63, 63))
ac32bf
+			rank1 = EXTRACT(e->misc, 51, 55);
ac32bf
+
ac32bf
+		/*
ac32bf
+		 * FIXME: The conversion from rank to dimm requires to parse the
ac32bf
+		 * DMI tables and call failrank2dimm().
ac32bf
+		 */
ac32bf
+		if (rank0 != -1 && rank1 != -1)
ac32bf
+			mce_snprintf(e->mc_location, "ranks=%d and %d",
ac32bf
+					     rank0, rank1);
ac32bf
+		else if (rank0 != -1)
ac32bf
+			mce_snprintf(e->mc_location, "rank=%d", rank0);
ac32bf
+	}
ac32bf
+}
ac32bf
diff --git a/mce-intel.c b/mce-intel.c
ac32bf
index 77b929b..032f4e0 100644
ac32bf
--- a/mce-intel.c
ac32bf
+++ b/mce-intel.c
ac32bf
@@ -397,6 +397,10 @@ int parse_intel_event(struct ras_events *ras, struct mce_event *e)
ac32bf
 		break;
ac32bf
 	case CPU_HASWELL_EPEX:
ac32bf
 		hsw_decode_model(ras, e);
ac32bf
+		break;
ac32bf
+	case CPU_KNIGHTS_LANDING:
ac32bf
+		knl_decode_model(ras, e);
ac32bf
+		break;
ac32bf
 	default:
ac32bf
 		break;
ac32bf
 	}
ac32bf
@@ -460,6 +464,7 @@ int set_intel_imc_log(enum cputype cputype, unsigned ncpus)
ac32bf
 	case CPU_SANDY_BRIDGE_EP:
ac32bf
 	case CPU_IVY_BRIDGE_EPEX:
ac32bf
 	case CPU_HASWELL_EPEX:
ac32bf
+	case CPU_KNIGHTS_LANDING:
ac32bf
 		msr = 0x17f;	/* MSR_ERROR_CONTROL */
ac32bf
 		bit = 0x2;	/* MemError Log Enable */
ac32bf
 		break;
ac32bf
diff --git a/ras-mce-handler.c b/ras-mce-handler.c
ac32bf
index 23f2488..3b0b05b 100644
ac32bf
--- a/ras-mce-handler.c
ac32bf
+++ b/ras-mce-handler.c
ac32bf
@@ -223,6 +223,7 @@ int register_mce_handler(struct ras_events *ras, unsigned ncpus)
ac32bf
 	case CPU_SANDY_BRIDGE_EP:
ac32bf
 	case CPU_IVY_BRIDGE_EPEX:
ac32bf
 	case CPU_HASWELL_EPEX:
ac32bf
+	case CPU_KNIGHTS_LANDING:
ac32bf
 		set_intel_imc_log(mce->cputype, ncpus);
ac32bf
 	default:
ac32bf
 		break;
ac32bf
diff --git a/ras-mce-handler.h b/ras-mce-handler.h
ac32bf
index 13b8f52..5466743 100644
ac32bf
--- a/ras-mce-handler.h
ac32bf
+++ b/ras-mce-handler.h
ac32bf
@@ -119,6 +119,7 @@ void dunnington_decode_model(struct mce_event *e);
ac32bf
 void snb_decode_model(struct ras_events *ras, struct mce_event *e);
ac32bf
 void ivb_decode_model(struct ras_events *ras, struct mce_event *e);
ac32bf
 void hsw_decode_model(struct ras_events *ras, struct mce_event *e);
ac32bf
+void knl_decode_model(struct ras_events *ras, struct mce_event *e);
ac32bf
 void tulsa_decode_model(struct mce_event *e);
ac32bf
 
ac32bf
 /* Software defined banks */
ac32bf
-- 
ac32bf
1.8.3.1
ac32bf