This patch extracts the DIMM label from the DMI table and puts this
information into sysfs. E.g. on a ThunderX2 system we found this now:

 # grep . /sys/devices/system/edac/mc/mc*/dimm*/dimm_label
 /sys/devices/system/edac/mc/mc0/dimm0/dimm_label:N0 DIMM_A0
 /sys/devices/system/edac/mc/mc0/dimm1/dimm_label:N0 DIMM_B0
 /sys/devices/system/edac/mc/mc0/dimm2/dimm_label:N0 DIMM_C0
 /sys/devices/system/edac/mc/mc0/dimm3/dimm_label:N0 DIMM_D0
 /sys/devices/system/edac/mc/mc0/dimm4/dimm_label:N0 DIMM_E0
 /sys/devices/system/edac/mc/mc0/dimm5/dimm_label:N0 DIMM_F0
 /sys/devices/system/edac/mc/mc0/dimm6/dimm_label:N0 DIMM_G0
 /sys/devices/system/edac/mc/mc0/dimm7/dimm_label:N0 DIMM_H0
 /sys/devices/system/edac/mc/mc1/dimm0/dimm_label:N1 DIMM_I0
 /sys/devices/system/edac/mc/mc1/dimm1/dimm_label:N1 DIMM_J0
 /sys/devices/system/edac/mc/mc1/dimm2/dimm_label:N1 DIMM_K0
 /sys/devices/system/edac/mc/mc1/dimm3/dimm_label:N1 DIMM_L0
 /sys/devices/system/edac/mc/mc1/dimm4/dimm_label:N1 DIMM_M0
 /sys/devices/system/edac/mc/mc1/dimm5/dimm_label:N1 DIMM_N0
 /sys/devices/system/edac/mc/mc1/dimm6/dimm_label:N1 DIMM_O0
 /sys/devices/system/edac/mc/mc1/dimm7/dimm_label:N1 DIMM_P0

Signed-off-by: Robert Richter <rrich...@marvell.com>
---
 drivers/edac/ghes_edac.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/edac/ghes_edac.c b/drivers/edac/ghes_edac.c
index e5fa977bcfd9..b8878ff498d1 100644
--- a/drivers/edac/ghes_edac.c
+++ b/drivers/edac/ghes_edac.c
@@ -254,10 +254,6 @@ static void ghes_edac_dmidecode(const struct dmi_header 
*dh, void *arg)
                dimm->dtype = DEV_UNKNOWN;
                dimm->grain = 128;              /* Likely, worse case */
 
-               /*
-                * FIXME: It shouldn't be hard to also fill the DIMM labels
-                */
-
                if (dimm->nr_pages) {
                        edac_dbg(1, "DIMM%i: %s size = %d MB%s\n",
                                mi->idx, edac_mem_types[dimm->mtype],
@@ -293,6 +289,7 @@ static int mem_info_setup(void)
 {
        struct ghes_dimm_info *dimm;
        bool enable_numa = true;
+       const char *bank, *device;
        int idx = 0;
 
        memset(&mem_info, 0, sizeof(mem_info));
@@ -312,6 +309,17 @@ static int mem_info_setup(void)
        dmi_walk(ghes_edac_set_nid, NULL);
 
        for_each_dimm(dimm) {
+               bank = device = NULL;
+               dmi_memdev_name(dimm->dimm_info.smbios_handle,
+                               &bank, &device);
+               if (bank && device) {
+                       snprintf(dimm->dimm_info.label,
+                               sizeof(dimm->dimm_info.label),
+                               "%s %s", bank, device);
+               } else {
+                       *dimm->dimm_info.label = '\0';
+               }
+
                if (dimm->numa_node == NUMA_NO_NODE) {
                        enable_numa = false;
                } else {
@@ -320,8 +328,11 @@ static int mem_info_setup(void)
                        mem_info.num_per_node[dimm->numa_node]++;
                }
 
-               edac_dbg(1, "DIMM%i: Found mem range [%pa-%pa] on node %d\n",
-                       dimm->idx, &dimm->start, &dimm->end, dimm->numa_node);
+               edac_dbg(1, "DIMM%i: Found mem range [%pa-%pa] on node %d, 
handle: 0x%.4x%s%s\n",
+                       dimm->idx, &dimm->start, &dimm->end, dimm->numa_node,
+                       dimm->dimm_info.smbios_handle,
+                       *dimm->dimm_info.label ? ", label: " : "",
+                       dimm->dimm_info.label);
        }
 
        mem_info.enable_numa = enable_numa;
@@ -387,6 +398,9 @@ static void mci_add_dimm_info(struct mem_ctl_info *mci)
                mci_dimm->dtype         = dmi_dimm->dtype;
                mci_dimm->grain         = dmi_dimm->grain;
                mci_dimm->smbios_handle = dmi_dimm->smbios_handle;
+
+               if (*dmi_dimm->label)
+                       strcpy(mci_dimm->label, dmi_dimm->label);
        }
 
        if (index != mci->tot_dimms)
-- 
2.20.1

Reply via email to