15 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/types.h>
21 #include <linux/sysctl.h>
24 #include <linux/slab.h>
27 #include <linux/list.h>
28 #include <linux/ctype.h>
30 #include <linux/bitops.h>
31 #include <asm/uaccess.h>
37 #define CREATE_TRACE_POINTS
38 #define TRACE_INCLUDE_PATH ../../include/ras
52 for (i = 0; i < mci->
n_layers; i++) {
66 #ifdef CONFIG_EDAC_DEBUG
71 edac_dbg(4,
" channel = %p\n", chan);
76 static void edac_mc_dump_dimm(
struct dimm_info *dimm,
int number)
82 edac_dbg(4,
"%s%i: %smapped as virtual row %d, chan %d\n",
83 dimm->
mci->mem_is_per_rank ?
"rank" :
"dimm",
92 static void edac_mc_dump_csrow(
struct csrow_info *csrow)
111 edac_dbg(3,
"\tmci->nr_csrows = %d, csrows = %p\n",
113 edac_dbg(3,
"\tmci->nr_dimms = %d, dimms = %p\n",
116 edac_dbg(3,
"\tmod_name:ctl_name = %s:%s\n",
128 "Reserved csrow type",
129 "Unknown csrow type",
130 "Fast page mode RAM",
131 "Extended data out RAM",
132 "Burst Extended data out RAM",
133 "Single data rate SDRAM",
134 "Registered single data rate SDRAM",
135 "Double data rate SDRAM",
136 "Registered Double data rate SDRAM",
138 "Unbuffered DDR2 RAM",
139 "Fully buffered DDR2",
140 "Registered DDR2 RAM",
142 "Unbuffered DDR3 RAM",
143 "Registered DDR3 RAM",
170 *p += size * n_elems;
181 if (size >
sizeof(
long))
182 align =
sizeof(
long long);
183 else if (size >
sizeof(
int))
184 align =
sizeof(
long);
185 else if (size >
sizeof(
short))
187 else if (size >
sizeof(
char))
188 align =
sizeof(
short);
192 r = (
unsigned long)p % align;
199 return (
void *)(((
unsigned long)ptr) + align -
r);
206 const unsigned int tot_dimms = mci->
tot_dimms;
208 const unsigned int tot_csrows = mci->
nr_csrows;
211 for (i = 0; i < tot_dimms; i++)
216 for (row = 0; row < tot_csrows; row++) {
220 for (chn = 0; chn < tot_channels; chn++)
269 unsigned tot_csrows = 1, tot_channels = 1, tot_errcount = 0;
272 bool per_rank =
false;
279 for (i = 0; i < n_layers; i++) {
280 tot_dimms *= layers[
i].
size;
281 if (layers[i].is_virt_csrow)
282 tot_csrows *= layers[
i].
size;
284 tot_channels *= layers[
i].
size;
297 for (i = 0; i < n_layers; i++) {
302 tot_errcount += 2 *
count;
305 edac_dbg(4,
"allocating %d error counters\n", tot_errcount);
307 size = ((
unsigned long)pvt) + sz_pvt;
309 edac_dbg(1,
"allocating %u bytes for mci data (%d %s, %d csrows/channels)\n",
312 per_rank ?
"ranks" :
"dimms",
313 tot_csrows * tot_channels);
323 for (i = 0; i < n_layers; i++) {
327 pvt = sz_pvt ? (((
char *)mci) + ((
unsigned long)pvt)) :
NULL;
330 mci->mc_idx = mc_num;
331 mci->tot_dimms = tot_dimms;
333 mci->n_layers = n_layers;
335 memcpy(mci->layers, layers,
sizeof(*layer) * n_layers);
336 mci->nr_csrows = tot_csrows;
337 mci->num_cschannel = tot_channels;
338 mci->mem_is_per_rank = per_rank;
343 mci->csrows = kcalloc(
sizeof(*mci->csrows), tot_csrows,
GFP_KERNEL);
346 for (row = 0; row < tot_csrows; row++) {
347 csr = kzalloc(
sizeof(**mci->csrows),
GFP_KERNEL);
350 mci->csrows[row] = csr;
359 for (chn = 0; chn < tot_channels; chn++) {
372 mci->dimms = kcalloc(
sizeof(*mci->dimms), tot_dimms,
GFP_KERNEL);
376 memset(&pos, 0,
sizeof(pos));
379 for (i = 0; i < tot_dimms; i++) {
380 chan = mci->csrows[row]->channels[
chn];
381 off =
EDAC_DIMM_OFF(layer, n_layers, pos[0], pos[1], pos[2]);
382 if (off < 0 || off >= tot_dimms) {
387 dimm = kzalloc(
sizeof(**mci->dimms),
GFP_KERNEL);
390 mci->dimms[off] = dimm;
396 len =
sizeof(dimm->
label);
398 n =
snprintf(p, len,
"mc#%u", mc_num);
401 for (j = 0; j < n_layers; j++) {
421 if (chn == tot_channels) {
427 if (row == tot_csrows) {
434 for (j = n_layers - 1; j >= 0; j--) {
436 if (pos[j] < layers[j].size)
472 if (!device_is_registered(&mci->
dev)) {
500 if (mci->
pdev == dev)
511 static int edac_mc_assert_error_check_and_clear(
void)
528 static void edac_mc_workq_function(
struct work_struct *work_req)
530 struct delayed_work *d_work = to_delayed_work(work_req);
542 if (edac_mc_assert_error_check_and_clear() && (mci->
edac_check !=
NULL))
581 static void edac_mc_workq_teardown(
struct mem_ctl_info *mci)
590 edac_dbg(0,
"not canceled, flush the queue\n");
613 edac_mc_workq_setup(mci, (
unsigned long) value);
629 static int add_mc_to_global_list(
struct mem_ctl_info *mci)
634 insert_before = &mc_devices;
647 insert_before =
item;
652 list_add_tail_rcu(&mci->
link, insert_before);
658 "%s (%s) %s %s already assigned %d\n",
dev_name(p->
pdev),
664 "bug in low-level driver: attempt to assign\n"
665 " duplicate mc_idx %d in %s()\n", p->
mc_idx, __func__);
669 static void del_mc_from_global_list(
struct mem_ctl_info *mci)
672 list_del_rcu(&mci->
link);
678 INIT_LIST_HEAD(&mci->
link);
724 #ifdef CONFIG_EDAC_DEBUG
725 if (edac_debug_level >= 3)
726 edac_mc_dump_mci(mci);
728 if (edac_debug_level >= 4) {
737 nr_pages += csrow->
channels[j]->dimm->nr_pages;
740 edac_mc_dump_csrow(csrow);
742 if (csrow->
channels[j]->dimm->nr_pages)
743 edac_mc_dump_channel(csrow->
channels[j]);
746 if (mci->
dimms[i]->nr_pages)
747 edac_mc_dump_dimm(mci->
dimms[i], i);
752 if (add_mc_to_global_list(mci))
760 "failed to create sysfs device\n");
782 del_mc_from_global_list(mci);
812 del_mc_from_global_list(mci);
816 edac_mc_workq_teardown(mci);
825 "Removed device %d for %s %s: DEV %s\n", mci->
mc_idx,
832 static void edac_mc_scrub_block(
unsigned long page,
unsigned long offset,
837 unsigned long flags = 0;
854 atomic_scrub(virt_addr + offset, size);
882 edac_dbg(3,
"MC%d: first(0x%lx) page(0x%lx) last(0x%lx) mask(0x%lx)\n",
898 "could not look up page error address %lx\n",
899 (
unsigned long)page);
914 bool enable_per_layer_report,
922 if (!enable_per_layer_report) {
927 for (i = 0; i < mci->
n_layers; i++) {
933 if (i < mci->n_layers - 1)
934 index *= mci->
layers[i + 1].size;
939 bool enable_per_layer_report,
940 const int pos[EDAC_MAX_LAYERS],
947 if (!enable_per_layer_report) {
952 for (i = 0; i < mci->
n_layers; i++) {
958 if (i < mci->n_layers - 1)
959 index *= mci->
layers[i + 1].size;
964 const u16 error_count,
965 const int pos[EDAC_MAX_LAYERS],
967 const char *location,
970 const char *other_detail,
971 const bool enable_per_layer_report,
972 const unsigned long page_frame_number,
976 unsigned long remapped_page;
979 if (other_detail && *other_detail)
981 "%d CE %s on %s (%s %s - %s)\n",
983 msg, label, location,
984 detail, other_detail);
987 "%d CE %s on %s (%s %s)\n",
989 msg, label, location,
992 edac_inc_ce_error(mci, enable_per_layer_report,
pos, error_count);
1010 edac_mc_scrub_block(remapped_page,
1011 offset_in_page, grain);
1016 const u16 error_count,
1017 const int pos[EDAC_MAX_LAYERS],
1019 const char *location,
1022 const char *other_detail,
1023 const bool enable_per_layer_report)
1026 if (other_detail && *other_detail)
1028 "%d UE %s on %s (%s %s - %s)\n",
1030 msg, label, location, detail,
1034 "%d UE %s on %s (%s %s)\n",
1036 msg, label, location, detail);
1040 if (other_detail && *other_detail)
1041 panic(
"UE %s on %s (%s%s - %s)\n",
1042 msg, label, location, detail, other_detail);
1044 panic(
"UE %s on %s (%s%s)\n",
1045 msg, label, location, detail);
1048 edac_inc_ue_error(mci, enable_per_layer_report,
pos, error_count);
1051 #define OTHER_LABEL " or "
1073 const u16 error_count,
1074 const unsigned long page_frame_number,
1075 const unsigned long offset_in_page,
1076 const unsigned long syndrome,
1077 const int top_layer,
1078 const int mid_layer,
1079 const int low_layer,
1081 const char *other_detail)
1084 char detail[80], location[80];
1087 int row = -1,
chan = -1;
1091 bool enable_per_layer_report =
false;
1102 for (i = 0; i < mci->
n_layers; i++) {
1103 if (pos[i] >= (
int)mci->
layers[i].size) {
1110 "INTERNAL ERROR: %s value is out of range (%d >= %d)\n",
1111 edac_layer_name[mci->
layers[i].type],
1112 pos[i], mci->
layers[i].size);
1122 enable_per_layer_report =
true;
1142 if (top_layer >= 0 && top_layer != dimm->
location[0])
1144 if (mid_layer >= 0 && mid_layer != dimm->
location[1])
1146 if (low_layer >= 0 && low_layer != dimm->
location[2])
1150 if (dimm->
grain > grain)
1151 grain = dimm->
grain;
1159 if (enable_per_layer_report && dimm->
nr_pages) {
1172 edac_dbg(4,
"%s csrows map: (%d,%d)\n",
1177 else if (row >= 0 && row != dimm->
csrow)
1187 if (!enable_per_layer_report) {
1188 strcpy(label,
"any memory");
1190 edac_dbg(4,
"csrow/channel to increment: (%d,%d)\n", row,
chan);
1192 strcpy(label,
"unknown memory");
1195 mci->
csrows[row]->ce_count += error_count;
1197 mci->
csrows[row]->channels[
chan]->ce_count += error_count;
1201 mci->
csrows[row]->ue_count += error_count;
1206 for (i = 0; i < mci->
n_layers; i++) {
1211 edac_layer_name[mci->
layers[i].type],
1219 grain_bits = fls_long(grain) + 1;
1220 trace_mc_event(type, msg, label, error_count,
1221 mci->
mc_idx, top_layer, mid_layer, low_layer,
1223 grain_bits, syndrome, other_detail);
1228 "page:0x%lx offset:0x%lx grain:%ld syndrome:0x%lx",
1229 page_frame_number, offset_in_page,
1231 edac_ce_error(mci, error_count, pos, msg, location, label,
1232 detail, other_detail, enable_per_layer_report,
1233 page_frame_number, offset_in_page, grain);
1236 "page:0x%lx offset:0x%lx grain:%ld",
1237 page_frame_number, offset_in_page, grain);
1239 edac_ue_error(mci, error_count, pos, msg, location, label,
1240 detail, other_detail, enable_per_layer_report);