drivers/edac: split out functions to unique files
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / edac / edac_mc.c
CommitLineData
da9bb1d2
AC
1/*
2 * edac_mc kernel module
49c0dab7 3 * (C) 2005, 2006 Linux Networx (http://lnxi.com)
da9bb1d2
AC
4 * This file may be distributed under the terms of the
5 * GNU General Public License.
6 *
7 * Written by Thayne Harbaugh
8 * Based on work by Dan Hollis <goemon at anime dot net> and others.
9 * http://www.anime.net/~goemon/linux-ecc/
10 *
11 * Modified by Dave Peterson and Doug Thompson
12 *
13 */
14
da9bb1d2
AC
15#include <linux/module.h>
16#include <linux/proc_fs.h>
17#include <linux/kernel.h>
18#include <linux/types.h>
19#include <linux/smp.h>
20#include <linux/init.h>
21#include <linux/sysctl.h>
22#include <linux/highmem.h>
23#include <linux/timer.h>
24#include <linux/slab.h>
25#include <linux/jiffies.h>
26#include <linux/spinlock.h>
27#include <linux/list.h>
28#include <linux/sysdev.h>
29#include <linux/ctype.h>
da9bb1d2
AC
30#include <asm/uaccess.h>
31#include <asm/page.h>
32#include <asm/edac.h>
da9bb1d2 33#include "edac_mc.h"
7c9281d7 34#include "edac_module.h"
da9bb1d2 35
da9bb1d2 36
da9bb1d2
AC
37/* lock to memory controller's control array */
38static DECLARE_MUTEX(mem_ctls_mutex);
39static struct list_head mc_devices = LIST_HEAD_INIT(mc_devices);
40
da9bb1d2
AC
41#ifdef CONFIG_EDAC_DEBUG
42
2da1c119 43static void edac_mc_dump_channel(struct channel_info *chan)
da9bb1d2
AC
44{
45 debugf4("\tchannel = %p\n", chan);
46 debugf4("\tchannel->chan_idx = %d\n", chan->chan_idx);
47 debugf4("\tchannel->ce_count = %d\n", chan->ce_count);
48 debugf4("\tchannel->label = '%s'\n", chan->label);
49 debugf4("\tchannel->csrow = %p\n\n", chan->csrow);
50}
51
2da1c119 52static void edac_mc_dump_csrow(struct csrow_info *csrow)
da9bb1d2
AC
53{
54 debugf4("\tcsrow = %p\n", csrow);
55 debugf4("\tcsrow->csrow_idx = %d\n", csrow->csrow_idx);
56 debugf4("\tcsrow->first_page = 0x%lx\n",
57 csrow->first_page);
58 debugf4("\tcsrow->last_page = 0x%lx\n", csrow->last_page);
59 debugf4("\tcsrow->page_mask = 0x%lx\n", csrow->page_mask);
60 debugf4("\tcsrow->nr_pages = 0x%x\n", csrow->nr_pages);
61 debugf4("\tcsrow->nr_channels = %d\n",
62 csrow->nr_channels);
63 debugf4("\tcsrow->channels = %p\n", csrow->channels);
64 debugf4("\tcsrow->mci = %p\n\n", csrow->mci);
65}
66
2da1c119 67static void edac_mc_dump_mci(struct mem_ctl_info *mci)
da9bb1d2
AC
68{
69 debugf3("\tmci = %p\n", mci);
70 debugf3("\tmci->mtype_cap = %lx\n", mci->mtype_cap);
71 debugf3("\tmci->edac_ctl_cap = %lx\n", mci->edac_ctl_cap);
72 debugf3("\tmci->edac_cap = %lx\n", mci->edac_cap);
73 debugf4("\tmci->edac_check = %p\n", mci->edac_check);
74 debugf3("\tmci->nr_csrows = %d, csrows = %p\n",
75 mci->nr_csrows, mci->csrows);
37f04581 76 debugf3("\tdev = %p\n", mci->dev);
da9bb1d2
AC
77 debugf3("\tmod_name:ctl_name = %s:%s\n",
78 mci->mod_name, mci->ctl_name);
79 debugf3("\tpvt_info = %p\n\n", mci->pvt_info);
80}
81
e7ecd891 82#endif /* CONFIG_EDAC_DEBUG */
da9bb1d2
AC
83
84/* 'ptr' points to a possibly unaligned item X such that sizeof(X) is 'size'.
85 * Adjust 'ptr' so that its alignment is at least as stringent as what the
86 * compiler would provide for X and return the aligned result.
87 *
88 * If 'size' is a constant, the compiler will optimize this whole function
89 * down to either a no-op or the addition of a constant to the value of 'ptr'.
90 */
e7ecd891 91static inline char * align_ptr(void *ptr, unsigned size)
da9bb1d2
AC
92{
93 unsigned align, r;
94
95 /* Here we assume that the alignment of a "long long" is the most
96 * stringent alignment that the compiler will ever provide by default.
97 * As far as I know, this is a reasonable assumption.
98 */
99 if (size > sizeof(long))
100 align = sizeof(long long);
101 else if (size > sizeof(int))
102 align = sizeof(long);
103 else if (size > sizeof(short))
104 align = sizeof(int);
105 else if (size > sizeof(char))
106 align = sizeof(short);
107 else
108 return (char *) ptr;
109
110 r = size % align;
111
112 if (r == 0)
113 return (char *) ptr;
114
115 return (char *) (((unsigned long) ptr) + align - r);
116}
117
da9bb1d2
AC
118/**
119 * edac_mc_alloc: Allocate a struct mem_ctl_info structure
120 * @size_pvt: size of private storage needed
121 * @nr_csrows: Number of CWROWS needed for this MC
122 * @nr_chans: Number of channels for the MC
123 *
124 * Everything is kmalloc'ed as one big chunk - more efficient.
125 * Only can be used if all structures have the same lifetime - otherwise
126 * you have to allocate and initialize your own structures.
127 *
128 * Use edac_mc_free() to free mc structures allocated by this function.
129 *
130 * Returns:
131 * NULL allocation failed
132 * struct mem_ctl_info pointer
133 */
134struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows,
e7ecd891 135 unsigned nr_chans)
da9bb1d2
AC
136{
137 struct mem_ctl_info *mci;
138 struct csrow_info *csi, *csrow;
139 struct channel_info *chi, *chp, *chan;
140 void *pvt;
141 unsigned size;
142 int row, chn;
143
144 /* Figure out the offsets of the various items from the start of an mc
145 * structure. We want the alignment of each item to be at least as
146 * stringent as what the compiler would provide if we could simply
147 * hardcode everything into a single struct.
148 */
149 mci = (struct mem_ctl_info *) 0;
150 csi = (struct csrow_info *)align_ptr(&mci[1], sizeof(*csi));
151 chi = (struct channel_info *)
152 align_ptr(&csi[nr_csrows], sizeof(*chi));
153 pvt = align_ptr(&chi[nr_chans * nr_csrows], sz_pvt);
154 size = ((unsigned long) pvt) + sz_pvt;
155
156 if ((mci = kmalloc(size, GFP_KERNEL)) == NULL)
157 return NULL;
158
159 /* Adjust pointers so they point within the memory we just allocated
160 * rather than an imaginary chunk of memory located at address 0.
161 */
162 csi = (struct csrow_info *) (((char *) mci) + ((unsigned long) csi));
163 chi = (struct channel_info *) (((char *) mci) + ((unsigned long) chi));
164 pvt = sz_pvt ? (((char *) mci) + ((unsigned long) pvt)) : NULL;
165
e7ecd891 166 memset(mci, 0, size); /* clear all fields */
da9bb1d2
AC
167 mci->csrows = csi;
168 mci->pvt_info = pvt;
169 mci->nr_csrows = nr_csrows;
170
171 for (row = 0; row < nr_csrows; row++) {
172 csrow = &csi[row];
173 csrow->csrow_idx = row;
174 csrow->mci = mci;
175 csrow->nr_channels = nr_chans;
176 chp = &chi[row * nr_chans];
177 csrow->channels = chp;
178
179 for (chn = 0; chn < nr_chans; chn++) {
180 chan = &chp[chn];
181 chan->chan_idx = chn;
182 chan->csrow = csrow;
183 }
184 }
185
186 return mci;
187}
9110540f 188EXPORT_SYMBOL_GPL(edac_mc_alloc);
da9bb1d2 189
da9bb1d2
AC
190/**
191 * edac_mc_free: Free a previously allocated 'mci' structure
192 * @mci: pointer to a struct mem_ctl_info structure
da9bb1d2
AC
193 */
194void edac_mc_free(struct mem_ctl_info *mci)
195{
472678eb 196 kfree(mci);
da9bb1d2 197}
9110540f 198EXPORT_SYMBOL_GPL(edac_mc_free);
da9bb1d2 199
37f04581 200static struct mem_ctl_info *find_mci_by_dev(struct device *dev)
da9bb1d2
AC
201{
202 struct mem_ctl_info *mci;
203 struct list_head *item;
204
537fba28 205 debugf3("%s()\n", __func__);
da9bb1d2
AC
206
207 list_for_each(item, &mc_devices) {
208 mci = list_entry(item, struct mem_ctl_info, link);
209
37f04581 210 if (mci->dev == dev)
da9bb1d2
AC
211 return mci;
212 }
213
214 return NULL;
215}
216
2d7bbb91
DT
217/* Return 0 on success, 1 on failure.
218 * Before calling this function, caller must
219 * assign a unique value to mci->mc_idx.
220 */
221static int add_mc_to_global_list (struct mem_ctl_info *mci)
da9bb1d2
AC
222{
223 struct list_head *item, *insert_before;
224 struct mem_ctl_info *p;
da9bb1d2 225
2d7bbb91 226 insert_before = &mc_devices;
da9bb1d2 227
2d7bbb91
DT
228 if (unlikely((p = find_mci_by_dev(mci->dev)) != NULL))
229 goto fail0;
da9bb1d2 230
2d7bbb91
DT
231 list_for_each(item, &mc_devices) {
232 p = list_entry(item, struct mem_ctl_info, link);
da9bb1d2 233
2d7bbb91
DT
234 if (p->mc_idx >= mci->mc_idx) {
235 if (unlikely(p->mc_idx == mci->mc_idx))
236 goto fail1;
da9bb1d2 237
2d7bbb91
DT
238 insert_before = item;
239 break;
da9bb1d2 240 }
da9bb1d2
AC
241 }
242
243 list_add_tail_rcu(&mci->link, insert_before);
244 return 0;
2d7bbb91
DT
245
246fail0:
247 edac_printk(KERN_WARNING, EDAC_MC,
248 "%s (%s) %s %s already assigned %d\n", p->dev->bus_id,
249 dev_name(p->dev), p->mod_name, p->ctl_name, p->mc_idx);
250 return 1;
251
252fail1:
253 edac_printk(KERN_WARNING, EDAC_MC,
254 "bug in low-level driver: attempt to assign\n"
255 " duplicate mc_idx %d in %s()\n", p->mc_idx, __func__);
256 return 1;
da9bb1d2
AC
257}
258
e7ecd891 259static void complete_mc_list_del(struct rcu_head *head)
a1d03fcc
DP
260{
261 struct mem_ctl_info *mci;
262
263 mci = container_of(head, struct mem_ctl_info, rcu);
264 INIT_LIST_HEAD(&mci->link);
265 complete(&mci->complete);
266}
267
e7ecd891 268static void del_mc_from_global_list(struct mem_ctl_info *mci)
a1d03fcc
DP
269{
270 list_del_rcu(&mci->link);
271 init_completion(&mci->complete);
272 call_rcu(&mci->rcu, complete_mc_list_del);
273 wait_for_completion(&mci->complete);
274}
275
5da0831c
DT
276/**
277 * edac_mc_find: Search for a mem_ctl_info structure whose index is 'idx'.
278 *
279 * If found, return a pointer to the structure.
280 * Else return NULL.
281 *
282 * Caller must hold mem_ctls_mutex.
283 */
284struct mem_ctl_info * edac_mc_find(int idx)
285{
286 struct list_head *item;
287 struct mem_ctl_info *mci;
288
289 list_for_each(item, &mc_devices) {
290 mci = list_entry(item, struct mem_ctl_info, link);
291
292 if (mci->mc_idx >= idx) {
293 if (mci->mc_idx == idx)
294 return mci;
295
296 break;
297 }
298 }
299
300 return NULL;
301}
302EXPORT_SYMBOL(edac_mc_find);
303
da9bb1d2 304/**
472678eb
DP
305 * edac_mc_add_mc: Insert the 'mci' structure into the mci global list and
306 * create sysfs entries associated with mci structure
da9bb1d2 307 * @mci: pointer to the mci structure to be added to the list
2d7bbb91 308 * @mc_idx: A unique numeric identifier to be assigned to the 'mci' structure.
da9bb1d2
AC
309 *
310 * Return:
311 * 0 Success
312 * !0 Failure
313 */
314
315/* FIXME - should a warning be printed if no error detection? correction? */
2d7bbb91 316int edac_mc_add_mc(struct mem_ctl_info *mci, int mc_idx)
da9bb1d2 317{
537fba28 318 debugf0("%s()\n", __func__);
2d7bbb91 319 mci->mc_idx = mc_idx;
da9bb1d2
AC
320#ifdef CONFIG_EDAC_DEBUG
321 if (edac_debug_level >= 3)
322 edac_mc_dump_mci(mci);
e7ecd891 323
da9bb1d2
AC
324 if (edac_debug_level >= 4) {
325 int i;
326
327 for (i = 0; i < mci->nr_csrows; i++) {
328 int j;
e7ecd891 329
da9bb1d2
AC
330 edac_mc_dump_csrow(&mci->csrows[i]);
331 for (j = 0; j < mci->csrows[i].nr_channels; j++)
e7ecd891
DP
332 edac_mc_dump_channel(
333 &mci->csrows[i].channels[j]);
da9bb1d2
AC
334 }
335 }
336#endif
337 down(&mem_ctls_mutex);
338
339 if (add_mc_to_global_list(mci))
028a7b6d 340 goto fail0;
da9bb1d2
AC
341
342 /* set load time so that error rate can be tracked */
343 mci->start_time = jiffies;
344
9794f33d 345 if (edac_create_sysfs_mci_device(mci)) {
346 edac_mc_printk(mci, KERN_WARNING,
537fba28 347 "failed to create sysfs device\n");
9794f33d 348 goto fail1;
349 }
da9bb1d2
AC
350
351 /* Report action taken */
37f04581
DT
352 edac_mc_printk(mci, KERN_INFO, "Giving out device to %s %s: DEV %s\n",
353 mci->mod_name, mci->ctl_name, dev_name(mci->dev));
da9bb1d2 354
028a7b6d
DP
355 up(&mem_ctls_mutex);
356 return 0;
da9bb1d2 357
028a7b6d
DP
358fail1:
359 del_mc_from_global_list(mci);
360
361fail0:
da9bb1d2 362 up(&mem_ctls_mutex);
028a7b6d 363 return 1;
da9bb1d2 364}
9110540f 365EXPORT_SYMBOL_GPL(edac_mc_add_mc);
da9bb1d2 366
da9bb1d2 367/**
472678eb
DP
368 * edac_mc_del_mc: Remove sysfs entries for specified mci structure and
369 * remove mci structure from global list
37f04581 370 * @pdev: Pointer to 'struct device' representing mci structure to remove.
da9bb1d2 371 *
18dbc337 372 * Return pointer to removed mci structure, or NULL if device not found.
da9bb1d2 373 */
37f04581 374struct mem_ctl_info * edac_mc_del_mc(struct device *dev)
da9bb1d2 375{
18dbc337 376 struct mem_ctl_info *mci;
da9bb1d2 377
18dbc337 378 debugf0("MC: %s()\n", __func__);
da9bb1d2 379 down(&mem_ctls_mutex);
18dbc337 380
37f04581 381 if ((mci = find_mci_by_dev(dev)) == NULL) {
18dbc337
DP
382 up(&mem_ctls_mutex);
383 return NULL;
384 }
385
386 edac_remove_sysfs_mci_device(mci);
da9bb1d2 387 del_mc_from_global_list(mci);
18dbc337 388 up(&mem_ctls_mutex);
537fba28 389 edac_printk(KERN_INFO, EDAC_MC,
37f04581
DT
390 "Removed device %d for %s %s: DEV %s\n", mci->mc_idx,
391 mci->mod_name, mci->ctl_name, dev_name(mci->dev));
18dbc337 392 return mci;
da9bb1d2 393}
9110540f 394EXPORT_SYMBOL_GPL(edac_mc_del_mc);
da9bb1d2 395
2da1c119
AB
396static void edac_mc_scrub_block(unsigned long page, unsigned long offset,
397 u32 size)
da9bb1d2
AC
398{
399 struct page *pg;
400 void *virt_addr;
401 unsigned long flags = 0;
402
537fba28 403 debugf3("%s()\n", __func__);
da9bb1d2
AC
404
405 /* ECC error page was not in our memory. Ignore it. */
406 if(!pfn_valid(page))
407 return;
408
409 /* Find the actual page structure then map it and fix */
410 pg = pfn_to_page(page);
411
412 if (PageHighMem(pg))
413 local_irq_save(flags);
414
415 virt_addr = kmap_atomic(pg, KM_BOUNCE_READ);
416
417 /* Perform architecture specific atomic scrub operation */
418 atomic_scrub(virt_addr + offset, size);
419
420 /* Unmap and complete */
421 kunmap_atomic(virt_addr, KM_BOUNCE_READ);
422
423 if (PageHighMem(pg))
424 local_irq_restore(flags);
425}
426
da9bb1d2 427/* FIXME - should return -1 */
e7ecd891 428int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci, unsigned long page)
da9bb1d2
AC
429{
430 struct csrow_info *csrows = mci->csrows;
431 int row, i;
432
537fba28 433 debugf1("MC%d: %s(): 0x%lx\n", mci->mc_idx, __func__, page);
da9bb1d2
AC
434 row = -1;
435
436 for (i = 0; i < mci->nr_csrows; i++) {
437 struct csrow_info *csrow = &csrows[i];
438
439 if (csrow->nr_pages == 0)
440 continue;
441
537fba28
DP
442 debugf3("MC%d: %s(): first(0x%lx) page(0x%lx) last(0x%lx) "
443 "mask(0x%lx)\n", mci->mc_idx, __func__,
444 csrow->first_page, page, csrow->last_page,
445 csrow->page_mask);
da9bb1d2
AC
446
447 if ((page >= csrow->first_page) &&
448 (page <= csrow->last_page) &&
449 ((page & csrow->page_mask) ==
450 (csrow->first_page & csrow->page_mask))) {
451 row = i;
452 break;
453 }
454 }
455
456 if (row == -1)
537fba28
DP
457 edac_mc_printk(mci, KERN_ERR,
458 "could not look up page error address %lx\n",
459 (unsigned long) page);
da9bb1d2
AC
460
461 return row;
462}
9110540f 463EXPORT_SYMBOL_GPL(edac_mc_find_csrow_by_page);
da9bb1d2 464
da9bb1d2
AC
465/* FIXME - setable log (warning/emerg) levels */
466/* FIXME - integrate with evlog: http://evlog.sourceforge.net/ */
467void edac_mc_handle_ce(struct mem_ctl_info *mci,
e7ecd891
DP
468 unsigned long page_frame_number, unsigned long offset_in_page,
469 unsigned long syndrome, int row, int channel, const char *msg)
da9bb1d2
AC
470{
471 unsigned long remapped_page;
472
537fba28 473 debugf3("MC%d: %s()\n", mci->mc_idx, __func__);
da9bb1d2
AC
474
475 /* FIXME - maybe make panic on INTERNAL ERROR an option */
476 if (row >= mci->nr_csrows || row < 0) {
477 /* something is wrong */
537fba28
DP
478 edac_mc_printk(mci, KERN_ERR,
479 "INTERNAL ERROR: row out of range "
480 "(%d >= %d)\n", row, mci->nr_csrows);
da9bb1d2
AC
481 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
482 return;
483 }
e7ecd891 484
da9bb1d2
AC
485 if (channel >= mci->csrows[row].nr_channels || channel < 0) {
486 /* something is wrong */
537fba28
DP
487 edac_mc_printk(mci, KERN_ERR,
488 "INTERNAL ERROR: channel out of range "
489 "(%d >= %d)\n", channel,
490 mci->csrows[row].nr_channels);
da9bb1d2
AC
491 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
492 return;
493 }
494
7c9281d7 495 if (edac_get_log_ce())
da9bb1d2 496 /* FIXME - put in DIMM location */
537fba28
DP
497 edac_mc_printk(mci, KERN_WARNING,
498 "CE page 0x%lx, offset 0x%lx, grain %d, syndrome "
499 "0x%lx, row %d, channel %d, label \"%s\": %s\n",
500 page_frame_number, offset_in_page,
501 mci->csrows[row].grain, syndrome, row, channel,
502 mci->csrows[row].channels[channel].label, msg);
da9bb1d2
AC
503
504 mci->ce_count++;
505 mci->csrows[row].ce_count++;
506 mci->csrows[row].channels[channel].ce_count++;
507
508 if (mci->scrub_mode & SCRUB_SW_SRC) {
509 /*
510 * Some MC's can remap memory so that it is still available
511 * at a different address when PCI devices map into memory.
512 * MC's that can't do this lose the memory where PCI devices
513 * are mapped. This mapping is MC dependant and so we call
514 * back into the MC driver for it to map the MC page to
515 * a physical (CPU) page which can then be mapped to a virtual
516 * page - which can then be scrubbed.
517 */
518 remapped_page = mci->ctl_page_to_phys ?
519 mci->ctl_page_to_phys(mci, page_frame_number) :
520 page_frame_number;
521
522 edac_mc_scrub_block(remapped_page, offset_in_page,
e7ecd891 523 mci->csrows[row].grain);
da9bb1d2
AC
524 }
525}
9110540f 526EXPORT_SYMBOL_GPL(edac_mc_handle_ce);
da9bb1d2 527
e7ecd891 528void edac_mc_handle_ce_no_info(struct mem_ctl_info *mci, const char *msg)
da9bb1d2 529{
7c9281d7 530 if (edac_get_log_ce())
537fba28
DP
531 edac_mc_printk(mci, KERN_WARNING,
532 "CE - no information available: %s\n", msg);
e7ecd891 533
da9bb1d2
AC
534 mci->ce_noinfo_count++;
535 mci->ce_count++;
536}
9110540f 537EXPORT_SYMBOL_GPL(edac_mc_handle_ce_no_info);
da9bb1d2 538
da9bb1d2 539void edac_mc_handle_ue(struct mem_ctl_info *mci,
e7ecd891
DP
540 unsigned long page_frame_number, unsigned long offset_in_page,
541 int row, const char *msg)
da9bb1d2
AC
542{
543 int len = EDAC_MC_LABEL_LEN * 4;
544 char labels[len + 1];
545 char *pos = labels;
546 int chan;
547 int chars;
548
537fba28 549 debugf3("MC%d: %s()\n", mci->mc_idx, __func__);
da9bb1d2
AC
550
551 /* FIXME - maybe make panic on INTERNAL ERROR an option */
552 if (row >= mci->nr_csrows || row < 0) {
553 /* something is wrong */
537fba28
DP
554 edac_mc_printk(mci, KERN_ERR,
555 "INTERNAL ERROR: row out of range "
556 "(%d >= %d)\n", row, mci->nr_csrows);
da9bb1d2
AC
557 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
558 return;
559 }
560
561 chars = snprintf(pos, len + 1, "%s",
e7ecd891 562 mci->csrows[row].channels[0].label);
da9bb1d2
AC
563 len -= chars;
564 pos += chars;
e7ecd891 565
da9bb1d2
AC
566 for (chan = 1; (chan < mci->csrows[row].nr_channels) && (len > 0);
567 chan++) {
568 chars = snprintf(pos, len + 1, ":%s",
e7ecd891 569 mci->csrows[row].channels[chan].label);
da9bb1d2
AC
570 len -= chars;
571 pos += chars;
572 }
573
7c9281d7 574 if (edac_get_log_ue())
537fba28
DP
575 edac_mc_printk(mci, KERN_EMERG,
576 "UE page 0x%lx, offset 0x%lx, grain %d, row %d, "
577 "labels \"%s\": %s\n", page_frame_number,
578 offset_in_page, mci->csrows[row].grain, row, labels,
579 msg);
da9bb1d2 580
7c9281d7 581 if (edac_get_panic_on_ue())
e7ecd891
DP
582 panic("EDAC MC%d: UE page 0x%lx, offset 0x%lx, grain %d, "
583 "row %d, labels \"%s\": %s\n", mci->mc_idx,
584 page_frame_number, offset_in_page,
585 mci->csrows[row].grain, row, labels, msg);
da9bb1d2
AC
586
587 mci->ue_count++;
588 mci->csrows[row].ue_count++;
589}
9110540f 590EXPORT_SYMBOL_GPL(edac_mc_handle_ue);
da9bb1d2 591
e7ecd891 592void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci, const char *msg)
da9bb1d2 593{
7c9281d7 594 if (edac_get_panic_on_ue())
da9bb1d2
AC
595 panic("EDAC MC%d: Uncorrected Error", mci->mc_idx);
596
7c9281d7 597 if (edac_get_log_ue())
537fba28
DP
598 edac_mc_printk(mci, KERN_WARNING,
599 "UE - no information available: %s\n", msg);
da9bb1d2
AC
600 mci->ue_noinfo_count++;
601 mci->ue_count++;
602}
9110540f 603EXPORT_SYMBOL_GPL(edac_mc_handle_ue_no_info);
da9bb1d2 604
da9bb1d2 605
9794f33d 606/*************************************************************
607 * On Fully Buffered DIMM modules, this help function is
608 * called to process UE events
609 */
610void edac_mc_handle_fbd_ue(struct mem_ctl_info *mci,
611 unsigned int csrow,
612 unsigned int channela,
613 unsigned int channelb,
614 char *msg)
615{
616 int len = EDAC_MC_LABEL_LEN * 4;
617 char labels[len + 1];
618 char *pos = labels;
619 int chars;
620
621 if (csrow >= mci->nr_csrows) {
622 /* something is wrong */
623 edac_mc_printk(mci, KERN_ERR,
624 "INTERNAL ERROR: row out of range (%d >= %d)\n",
625 csrow, mci->nr_csrows);
626 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
627 return;
628 }
629
630 if (channela >= mci->csrows[csrow].nr_channels) {
631 /* something is wrong */
632 edac_mc_printk(mci, KERN_ERR,
633 "INTERNAL ERROR: channel-a out of range "
634 "(%d >= %d)\n",
635 channela, mci->csrows[csrow].nr_channels);
636 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
637 return;
638 }
639
640 if (channelb >= mci->csrows[csrow].nr_channels) {
641 /* something is wrong */
642 edac_mc_printk(mci, KERN_ERR,
643 "INTERNAL ERROR: channel-b out of range "
644 "(%d >= %d)\n",
645 channelb, mci->csrows[csrow].nr_channels);
646 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
647 return;
648 }
649
650 mci->ue_count++;
651 mci->csrows[csrow].ue_count++;
652
653 /* Generate the DIMM labels from the specified channels */
654 chars = snprintf(pos, len + 1, "%s",
655 mci->csrows[csrow].channels[channela].label);
656 len -= chars; pos += chars;
657 chars = snprintf(pos, len + 1, "-%s",
658 mci->csrows[csrow].channels[channelb].label);
659
7c9281d7 660 if (edac_get_log_ue())
9794f33d 661 edac_mc_printk(mci, KERN_EMERG,
662 "UE row %d, channel-a= %d channel-b= %d "
663 "labels \"%s\": %s\n", csrow, channela, channelb,
664 labels, msg);
665
7c9281d7 666 if (edac_get_panic_on_ue())
9794f33d 667 panic("UE row %d, channel-a= %d channel-b= %d "
668 "labels \"%s\": %s\n", csrow, channela,
669 channelb, labels, msg);
670}
671EXPORT_SYMBOL(edac_mc_handle_fbd_ue);
672
673/*************************************************************
674 * On Fully Buffered DIMM modules, this help function is
675 * called to process CE events
676 */
677void edac_mc_handle_fbd_ce(struct mem_ctl_info *mci,
678 unsigned int csrow,
679 unsigned int channel,
680 char *msg)
681{
682
683 /* Ensure boundary values */
684 if (csrow >= mci->nr_csrows) {
685 /* something is wrong */
686 edac_mc_printk(mci, KERN_ERR,
687 "INTERNAL ERROR: row out of range (%d >= %d)\n",
688 csrow, mci->nr_csrows);
689 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
690 return;
691 }
692 if (channel >= mci->csrows[csrow].nr_channels) {
693 /* something is wrong */
694 edac_mc_printk(mci, KERN_ERR,
695 "INTERNAL ERROR: channel out of range (%d >= %d)\n",
696 channel, mci->csrows[csrow].nr_channels);
697 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
698 return;
699 }
700
7c9281d7 701 if (edac_get_log_ce())
9794f33d 702 /* FIXME - put in DIMM location */
703 edac_mc_printk(mci, KERN_WARNING,
704 "CE row %d, channel %d, label \"%s\": %s\n",
705 csrow, channel,
706 mci->csrows[csrow].channels[channel].label,
707 msg);
708
709 mci->ce_count++;
710 mci->csrows[csrow].ce_count++;
711 mci->csrows[csrow].channels[channel].ce_count++;
712}
713EXPORT_SYMBOL(edac_mc_handle_fbd_ce);
714
715
da9bb1d2
AC
716/*
717 * Iterate over all MC instances and check for ECC, et al, errors
718 */
7c9281d7 719void edac_check_mc_devices(void)
da9bb1d2 720{
da9bb1d2
AC
721 struct list_head *item;
722 struct mem_ctl_info *mci;
723
537fba28 724 debugf3("%s()\n", __func__);
18dbc337 725 down(&mem_ctls_mutex);
da9bb1d2
AC
726
727 list_for_each(item, &mc_devices) {
728 mci = list_entry(item, struct mem_ctl_info, link);
729
730 if (mci->edac_check != NULL)
731 mci->edac_check(mci);
732 }
733
18dbc337 734 up(&mem_ctls_mutex);
da9bb1d2 735}