drivers/edac: mod MC to use workq instead of kthread
[safe/jmp/linux-2.6] / drivers / edac / edac_mc.c
1 /*
2  * edac_mc kernel module
3  * (C) 2005, 2006 Linux Networx (http://lnxi.com)
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
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>
30 #include <linux/edac.h>
31 #include <asm/uaccess.h>
32 #include <asm/page.h>
33 #include <asm/edac.h>
34 #include "edac_core.h"
35 #include "edac_module.h"
36
37
38 /* lock to memory controller's control array */
39 static DEFINE_MUTEX(mem_ctls_mutex);
40 static struct list_head mc_devices = LIST_HEAD_INIT(mc_devices);
41
42 #ifdef CONFIG_EDAC_DEBUG
43
44 static void edac_mc_dump_channel(struct channel_info *chan)
45 {
46         debugf4("\tchannel = %p\n", chan);
47         debugf4("\tchannel->chan_idx = %d\n", chan->chan_idx);
48         debugf4("\tchannel->ce_count = %d\n", chan->ce_count);
49         debugf4("\tchannel->label = '%s'\n", chan->label);
50         debugf4("\tchannel->csrow = %p\n\n", chan->csrow);
51 }
52
53 static void edac_mc_dump_csrow(struct csrow_info *csrow)
54 {
55         debugf4("\tcsrow = %p\n", csrow);
56         debugf4("\tcsrow->csrow_idx = %d\n", csrow->csrow_idx);
57         debugf4("\tcsrow->first_page = 0x%lx\n",
58                 csrow->first_page);
59         debugf4("\tcsrow->last_page = 0x%lx\n", csrow->last_page);
60         debugf4("\tcsrow->page_mask = 0x%lx\n", csrow->page_mask);
61         debugf4("\tcsrow->nr_pages = 0x%x\n", csrow->nr_pages);
62         debugf4("\tcsrow->nr_channels = %d\n",
63                 csrow->nr_channels);
64         debugf4("\tcsrow->channels = %p\n", csrow->channels);
65         debugf4("\tcsrow->mci = %p\n\n", csrow->mci);
66 }
67
68 static void edac_mc_dump_mci(struct mem_ctl_info *mci)
69 {
70         debugf3("\tmci = %p\n", mci);
71         debugf3("\tmci->mtype_cap = %lx\n", mci->mtype_cap);
72         debugf3("\tmci->edac_ctl_cap = %lx\n", mci->edac_ctl_cap);
73         debugf3("\tmci->edac_cap = %lx\n", mci->edac_cap);
74         debugf4("\tmci->edac_check = %p\n", mci->edac_check);
75         debugf3("\tmci->nr_csrows = %d, csrows = %p\n",
76                 mci->nr_csrows, mci->csrows);
77         debugf3("\tdev = %p\n", mci->dev);
78         debugf3("\tmod_name:ctl_name = %s:%s\n",
79                 mci->mod_name, mci->ctl_name);
80         debugf3("\tpvt_info = %p\n\n", mci->pvt_info);
81 }
82
83 #endif  /* CONFIG_EDAC_DEBUG */
84
85 /* 'ptr' points to a possibly unaligned item X such that sizeof(X) is 'size'.
86  * Adjust 'ptr' so that its alignment is at least as stringent as what the
87  * compiler would provide for X and return the aligned result.
88  *
89  * If 'size' is a constant, the compiler will optimize this whole function
90  * down to either a no-op or the addition of a constant to the value of 'ptr'.
91  */
92 char * edac_align_ptr(void *ptr, unsigned size)
93 {
94         unsigned align, r;
95
96         /* Here we assume that the alignment of a "long long" is the most
97          * stringent alignment that the compiler will ever provide by default.
98          * As far as I know, this is a reasonable assumption.
99          */
100         if (size > sizeof(long))
101                 align = sizeof(long long);
102         else if (size > sizeof(int))
103                 align = sizeof(long);
104         else if (size > sizeof(short))
105                 align = sizeof(int);
106         else if (size > sizeof(char))
107                 align = sizeof(short);
108         else
109                 return (char *) ptr;
110
111         r = size % align;
112
113         if (r == 0)
114                 return (char *) ptr;
115
116         return (char *) (((unsigned long) ptr) + align - r);
117 }
118
119 /**
120  * edac_mc_alloc: Allocate a struct mem_ctl_info structure
121  * @size_pvt:   size of private storage needed
122  * @nr_csrows:  Number of CWROWS needed for this MC
123  * @nr_chans:   Number of channels for the MC
124  *
125  * Everything is kmalloc'ed as one big chunk - more efficient.
126  * Only can be used if all structures have the same lifetime - otherwise
127  * you have to allocate and initialize your own structures.
128  *
129  * Use edac_mc_free() to free mc structures allocated by this function.
130  *
131  * Returns:
132  *      NULL allocation failed
133  *      struct mem_ctl_info pointer
134  */
135 struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows,
136                 unsigned nr_chans)
137 {
138         struct mem_ctl_info *mci;
139         struct csrow_info *csi, *csrow;
140         struct channel_info *chi, *chp, *chan;
141         void *pvt;
142         unsigned size;
143         int row, chn;
144
145         /* Figure out the offsets of the various items from the start of an mc
146          * structure.  We want the alignment of each item to be at least as
147          * stringent as what the compiler would provide if we could simply
148          * hardcode everything into a single struct.
149          */
150         mci = (struct mem_ctl_info *) 0;
151         csi = (struct csrow_info *)edac_align_ptr(&mci[1], sizeof(*csi));
152         chi = (struct channel_info *)
153                         edac_align_ptr(&csi[nr_csrows], sizeof(*chi));
154         pvt = edac_align_ptr(&chi[nr_chans * nr_csrows], sz_pvt);
155         size = ((unsigned long) pvt) + sz_pvt;
156
157         if ((mci = kmalloc(size, GFP_KERNEL)) == NULL)
158                 return NULL;
159
160         /* Adjust pointers so they point within the memory we just allocated
161          * rather than an imaginary chunk of memory located at address 0.
162          */
163         csi = (struct csrow_info *) (((char *) mci) + ((unsigned long) csi));
164         chi = (struct channel_info *) (((char *) mci) + ((unsigned long) chi));
165         pvt = sz_pvt ? (((char *) mci) + ((unsigned long) pvt)) : NULL;
166
167         memset(mci, 0, size);  /* clear all fields */
168         mci->csrows = csi;
169         mci->pvt_info = pvt;
170         mci->nr_csrows = nr_csrows;
171
172         for (row = 0; row < nr_csrows; row++) {
173                 csrow = &csi[row];
174                 csrow->csrow_idx = row;
175                 csrow->mci = mci;
176                 csrow->nr_channels = nr_chans;
177                 chp = &chi[row * nr_chans];
178                 csrow->channels = chp;
179
180                 for (chn = 0; chn < nr_chans; chn++) {
181                         chan = &chp[chn];
182                         chan->chan_idx = chn;
183                         chan->csrow = csrow;
184                 }
185         }
186
187         mci->op_state = OP_ALLOC;
188
189         return mci;
190 }
191 EXPORT_SYMBOL_GPL(edac_mc_alloc);
192
193 /**
194  * edac_mc_free:  Free a previously allocated 'mci' structure
195  * @mci: pointer to a struct mem_ctl_info structure
196  */
197 void edac_mc_free(struct mem_ctl_info *mci)
198 {
199         kfree(mci);
200 }
201 EXPORT_SYMBOL_GPL(edac_mc_free);
202
203 static struct mem_ctl_info *find_mci_by_dev(struct device *dev)
204 {
205         struct mem_ctl_info *mci;
206         struct list_head *item;
207
208         debugf3("%s()\n", __func__);
209
210         list_for_each(item, &mc_devices) {
211                 mci = list_entry(item, struct mem_ctl_info, link);
212
213                 if (mci->dev == dev)
214                         return mci;
215         }
216
217         return NULL;
218 }
219
220 /*
221  * handler for EDAC to check if NMI type handler has asserted interrupt
222  */
223 static int edac_mc_assert_error_check_and_clear(void)
224 {
225         int vreg;
226
227         if(edac_op_state == EDAC_OPSTATE_POLL)
228                 return 1;
229
230         vreg = atomic_read(&edac_err_assert);
231         if(vreg) {
232                 atomic_set(&edac_err_assert, 0);
233                 return 1;
234         }
235
236         return 0;
237 }
238
239 /*
240  * edac_mc_workq_function
241  *      performs the operation scheduled by a workq request
242  */
243 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
244 static void edac_mc_workq_function(struct work_struct *work_req)
245 {
246         struct delayed_work *d_work = (struct delayed_work*) work_req;
247         struct mem_ctl_info *mci = to_edac_mem_ctl_work(d_work);
248 #else
249 static void edac_mc_workq_function(void *ptr)
250 {
251         struct mem_ctl_info *mci = (struct mem_ctl_info *) ptr;
252 #endif
253
254         mutex_lock(&mem_ctls_mutex);
255
256         /* Only poll controllers that are running polled and have a check */
257         if (edac_mc_assert_error_check_and_clear() && (mci->edac_check != NULL))
258                 mci->edac_check(mci);
259
260         /*
261          * FIXME: temp place holder for PCI checks,
262          * goes away when we break out PCI
263          */
264         edac_pci_do_parity_check();
265
266         mutex_unlock(&mem_ctls_mutex);
267
268         /* Reschedule */
269         queue_delayed_work(edac_workqueue, &mci->work, edac_mc_get_poll_msec());
270 }
271
272 /*
273  * edac_mc_workq_setup
274  *      initialize a workq item for this mci
275  *      passing in the new delay period in msec
276  */
277 void edac_mc_workq_setup(struct mem_ctl_info *mci, unsigned msec)
278 {
279         debugf0("%s()\n", __func__);
280
281 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
282         INIT_DELAYED_WORK(&mci->work, edac_mc_workq_function);
283 #else
284         INIT_WORK(&mci->work, edac_mc_workq_function, mci);
285 #endif
286         queue_delayed_work(edac_workqueue, &mci->work, msecs_to_jiffies(msec));
287 }
288
289 /*
290  * edac_mc_workq_teardown
291  *      stop the workq processing on this mci
292  */
293 void edac_mc_workq_teardown(struct mem_ctl_info *mci)
294 {
295         int status;
296
297         status = cancel_delayed_work(&mci->work);
298         if (status == 0) {
299                 /* workq instance might be running, wait for it */
300                 flush_workqueue(edac_workqueue);
301         }
302 }
303
304 /*
305  * edac_reset_delay_period
306  */
307
308 void edac_reset_delay_period(struct mem_ctl_info *mci, unsigned long value)
309 {
310         mutex_lock(&mem_ctls_mutex);
311
312         /* cancel the current workq request */
313         edac_mc_workq_teardown(mci);
314
315         /* restart the workq request, with new delay value */
316         edac_mc_workq_setup(mci, value);
317
318         mutex_unlock(&mem_ctls_mutex);
319 }
320
321 /* Return 0 on success, 1 on failure.
322  * Before calling this function, caller must
323  * assign a unique value to mci->mc_idx.
324  */
325 static int add_mc_to_global_list (struct mem_ctl_info *mci)
326 {
327         struct list_head *item, *insert_before;
328         struct mem_ctl_info *p;
329
330         insert_before = &mc_devices;
331
332         if (unlikely((p = find_mci_by_dev(mci->dev)) != NULL))
333                 goto fail0;
334
335         list_for_each(item, &mc_devices) {
336                 p = list_entry(item, struct mem_ctl_info, link);
337
338                 if (p->mc_idx >= mci->mc_idx) {
339                         if (unlikely(p->mc_idx == mci->mc_idx))
340                                 goto fail1;
341
342                         insert_before = item;
343                         break;
344                 }
345         }
346
347         list_add_tail_rcu(&mci->link, insert_before);
348         atomic_inc(&edac_handlers);
349         return 0;
350
351 fail0:
352         edac_printk(KERN_WARNING, EDAC_MC,
353                     "%s (%s) %s %s already assigned %d\n", p->dev->bus_id,
354                     dev_name(mci), p->mod_name, p->ctl_name, p->mc_idx);
355         return 1;
356
357 fail1:
358         edac_printk(KERN_WARNING, EDAC_MC,
359                     "bug in low-level driver: attempt to assign\n"
360                     "    duplicate mc_idx %d in %s()\n", p->mc_idx, __func__);
361         return 1;
362 }
363
364 static void complete_mc_list_del(struct rcu_head *head)
365 {
366         struct mem_ctl_info *mci;
367
368         mci = container_of(head, struct mem_ctl_info, rcu);
369         INIT_LIST_HEAD(&mci->link);
370         complete(&mci->complete);
371 }
372
373 static void del_mc_from_global_list(struct mem_ctl_info *mci)
374 {
375         atomic_dec(&edac_handlers);
376         list_del_rcu(&mci->link);
377         init_completion(&mci->complete);
378         call_rcu(&mci->rcu, complete_mc_list_del);
379         wait_for_completion(&mci->complete);
380 }
381
382 /**
383  * edac_mc_find: Search for a mem_ctl_info structure whose index is 'idx'.
384  *
385  * If found, return a pointer to the structure.
386  * Else return NULL.
387  *
388  * Caller must hold mem_ctls_mutex.
389  */
390 struct mem_ctl_info * edac_mc_find(int idx)
391 {
392         struct list_head *item;
393         struct mem_ctl_info *mci;
394
395         list_for_each(item, &mc_devices) {
396                 mci = list_entry(item, struct mem_ctl_info, link);
397
398                 if (mci->mc_idx >= idx) {
399                         if (mci->mc_idx == idx)
400                                 return mci;
401
402                         break;
403                 }
404         }
405
406         return NULL;
407 }
408 EXPORT_SYMBOL(edac_mc_find);
409
410 /**
411  * edac_mc_add_mc: Insert the 'mci' structure into the mci global list and
412  *                 create sysfs entries associated with mci structure
413  * @mci: pointer to the mci structure to be added to the list
414  * @mc_idx: A unique numeric identifier to be assigned to the 'mci' structure.
415  *
416  * Return:
417  *      0       Success
418  *      !0      Failure
419  */
420
421 /* FIXME - should a warning be printed if no error detection? correction? */
422 int edac_mc_add_mc(struct mem_ctl_info *mci, int mc_idx)
423 {
424         debugf0("%s()\n", __func__);
425         mci->mc_idx = mc_idx;
426 #ifdef CONFIG_EDAC_DEBUG
427         if (edac_debug_level >= 3)
428                 edac_mc_dump_mci(mci);
429
430         if (edac_debug_level >= 4) {
431                 int i;
432
433                 for (i = 0; i < mci->nr_csrows; i++) {
434                         int j;
435
436                         edac_mc_dump_csrow(&mci->csrows[i]);
437                         for (j = 0; j < mci->csrows[i].nr_channels; j++)
438                                 edac_mc_dump_channel(
439                                         &mci->csrows[i].channels[j]);
440                 }
441         }
442 #endif
443         mutex_lock(&mem_ctls_mutex);
444
445         if (add_mc_to_global_list(mci))
446                 goto fail0;
447
448         /* set load time so that error rate can be tracked */
449         mci->start_time = jiffies;
450
451         if (edac_create_sysfs_mci_device(mci)) {
452                 edac_mc_printk(mci, KERN_WARNING,
453                         "failed to create sysfs device\n");
454                 goto fail1;
455         }
456
457         /* If there IS a check routine, then we are running POLLED */
458         if (mci->edac_check != NULL) {
459                 /* This instance is NOW RUNNING */
460                 mci->op_state = OP_RUNNING_POLL;
461
462                 edac_mc_workq_setup(mci, edac_mc_get_poll_msec());
463         } else {
464                 mci->op_state = OP_RUNNING_INTERRUPT;
465         }
466
467         /* Report action taken */
468         edac_mc_printk(mci, KERN_INFO, "Giving out device to %s %s: DEV %s\n",
469                 mci->mod_name, mci->ctl_name, dev_name(mci));
470
471         mutex_unlock(&mem_ctls_mutex);
472         return 0;
473
474 fail1:
475         del_mc_from_global_list(mci);
476
477 fail0:
478         mutex_unlock(&mem_ctls_mutex);
479         return 1;
480 }
481 EXPORT_SYMBOL_GPL(edac_mc_add_mc);
482
483 /**
484  * edac_mc_del_mc: Remove sysfs entries for specified mci structure and
485  *                 remove mci structure from global list
486  * @pdev: Pointer to 'struct device' representing mci structure to remove.
487  *
488  * Return pointer to removed mci structure, or NULL if device not found.
489  */
490 struct mem_ctl_info * edac_mc_del_mc(struct device *dev)
491 {
492         struct mem_ctl_info *mci;
493
494         debugf0("MC: %s()\n", __func__);
495         mutex_lock(&mem_ctls_mutex);
496
497         if ((mci = find_mci_by_dev(dev)) == NULL) {
498                 mutex_unlock(&mem_ctls_mutex);
499                 return NULL;
500         }
501
502         /* marking MCI offline */
503         mci->op_state = OP_OFFLINE;
504
505         /* flush workq processes */
506         edac_mc_workq_teardown(mci);
507
508         edac_remove_sysfs_mci_device(mci);
509         del_mc_from_global_list(mci);
510         mutex_unlock(&mem_ctls_mutex);
511         edac_printk(KERN_INFO, EDAC_MC,
512                 "Removed device %d for %s %s: DEV %s\n", mci->mc_idx,
513                 mci->mod_name, mci->ctl_name, dev_name(mci));
514         return mci;
515 }
516 EXPORT_SYMBOL_GPL(edac_mc_del_mc);
517
518 static void edac_mc_scrub_block(unsigned long page, unsigned long offset,
519                                 u32 size)
520 {
521         struct page *pg;
522         void *virt_addr;
523         unsigned long flags = 0;
524
525         debugf3("%s()\n", __func__);
526
527         /* ECC error page was not in our memory. Ignore it. */
528         if(!pfn_valid(page))
529                 return;
530
531         /* Find the actual page structure then map it and fix */
532         pg = pfn_to_page(page);
533
534         if (PageHighMem(pg))
535                 local_irq_save(flags);
536
537         virt_addr = kmap_atomic(pg, KM_BOUNCE_READ);
538
539         /* Perform architecture specific atomic scrub operation */
540         atomic_scrub(virt_addr + offset, size);
541
542         /* Unmap and complete */
543         kunmap_atomic(virt_addr, KM_BOUNCE_READ);
544
545         if (PageHighMem(pg))
546                 local_irq_restore(flags);
547 }
548
549 /* FIXME - should return -1 */
550 int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci, unsigned long page)
551 {
552         struct csrow_info *csrows = mci->csrows;
553         int row, i;
554
555         debugf1("MC%d: %s(): 0x%lx\n", mci->mc_idx, __func__, page);
556         row = -1;
557
558         for (i = 0; i < mci->nr_csrows; i++) {
559                 struct csrow_info *csrow = &csrows[i];
560
561                 if (csrow->nr_pages == 0)
562                         continue;
563
564                 debugf3("MC%d: %s(): first(0x%lx) page(0x%lx) last(0x%lx) "
565                         "mask(0x%lx)\n", mci->mc_idx, __func__,
566                         csrow->first_page, page, csrow->last_page,
567                         csrow->page_mask);
568
569                 if ((page >= csrow->first_page) &&
570                     (page <= csrow->last_page) &&
571                     ((page & csrow->page_mask) ==
572                      (csrow->first_page & csrow->page_mask))) {
573                         row = i;
574                         break;
575                 }
576         }
577
578         if (row == -1)
579                 edac_mc_printk(mci, KERN_ERR,
580                         "could not look up page error address %lx\n",
581                         (unsigned long) page);
582
583         return row;
584 }
585 EXPORT_SYMBOL_GPL(edac_mc_find_csrow_by_page);
586
587 /* FIXME - setable log (warning/emerg) levels */
588 /* FIXME - integrate with evlog: http://evlog.sourceforge.net/ */
589 void edac_mc_handle_ce(struct mem_ctl_info *mci,
590                 unsigned long page_frame_number, unsigned long offset_in_page,
591                 unsigned long syndrome, int row, int channel, const char *msg)
592 {
593         unsigned long remapped_page;
594
595         debugf3("MC%d: %s()\n", mci->mc_idx, __func__);
596
597         /* FIXME - maybe make panic on INTERNAL ERROR an option */
598         if (row >= mci->nr_csrows || row < 0) {
599                 /* something is wrong */
600                 edac_mc_printk(mci, KERN_ERR,
601                         "INTERNAL ERROR: row out of range "
602                         "(%d >= %d)\n", row, mci->nr_csrows);
603                 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
604                 return;
605         }
606
607         if (channel >= mci->csrows[row].nr_channels || channel < 0) {
608                 /* something is wrong */
609                 edac_mc_printk(mci, KERN_ERR,
610                         "INTERNAL ERROR: channel out of range "
611                         "(%d >= %d)\n", channel,
612                         mci->csrows[row].nr_channels);
613                 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
614                 return;
615         }
616
617         if (edac_get_log_ce())
618                 /* FIXME - put in DIMM location */
619                 edac_mc_printk(mci, KERN_WARNING,
620                         "CE page 0x%lx, offset 0x%lx, grain %d, syndrome "
621                         "0x%lx, row %d, channel %d, label \"%s\": %s\n",
622                         page_frame_number, offset_in_page,
623                         mci->csrows[row].grain, syndrome, row, channel,
624                         mci->csrows[row].channels[channel].label, msg);
625
626         mci->ce_count++;
627         mci->csrows[row].ce_count++;
628         mci->csrows[row].channels[channel].ce_count++;
629
630         if (mci->scrub_mode & SCRUB_SW_SRC) {
631                 /*
632                  * Some MC's can remap memory so that it is still available
633                  * at a different address when PCI devices map into memory.
634                  * MC's that can't do this lose the memory where PCI devices
635                  * are mapped.  This mapping is MC dependant and so we call
636                  * back into the MC driver for it to map the MC page to
637                  * a physical (CPU) page which can then be mapped to a virtual
638                  * page - which can then be scrubbed.
639                  */
640                 remapped_page = mci->ctl_page_to_phys ?
641                     mci->ctl_page_to_phys(mci, page_frame_number) :
642                     page_frame_number;
643
644                 edac_mc_scrub_block(remapped_page, offset_in_page,
645                                         mci->csrows[row].grain);
646         }
647 }
648 EXPORT_SYMBOL_GPL(edac_mc_handle_ce);
649
650 void edac_mc_handle_ce_no_info(struct mem_ctl_info *mci, const char *msg)
651 {
652         if (edac_get_log_ce())
653                 edac_mc_printk(mci, KERN_WARNING,
654                         "CE - no information available: %s\n", msg);
655
656         mci->ce_noinfo_count++;
657         mci->ce_count++;
658 }
659 EXPORT_SYMBOL_GPL(edac_mc_handle_ce_no_info);
660
661 void edac_mc_handle_ue(struct mem_ctl_info *mci,
662                 unsigned long page_frame_number, unsigned long offset_in_page,
663                 int row, const char *msg)
664 {
665         int len = EDAC_MC_LABEL_LEN * 4;
666         char labels[len + 1];
667         char *pos = labels;
668         int chan;
669         int chars;
670
671         debugf3("MC%d: %s()\n", mci->mc_idx, __func__);
672
673         /* FIXME - maybe make panic on INTERNAL ERROR an option */
674         if (row >= mci->nr_csrows || row < 0) {
675                 /* something is wrong */
676                 edac_mc_printk(mci, KERN_ERR,
677                         "INTERNAL ERROR: row out of range "
678                         "(%d >= %d)\n", row, mci->nr_csrows);
679                 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
680                 return;
681         }
682
683         chars = snprintf(pos, len + 1, "%s",
684                         mci->csrows[row].channels[0].label);
685         len -= chars;
686         pos += chars;
687
688         for (chan = 1; (chan < mci->csrows[row].nr_channels) && (len > 0);
689              chan++) {
690                 chars = snprintf(pos, len + 1, ":%s",
691                                 mci->csrows[row].channels[chan].label);
692                 len -= chars;
693                 pos += chars;
694         }
695
696         if (edac_get_log_ue())
697                 edac_mc_printk(mci, KERN_EMERG,
698                         "UE page 0x%lx, offset 0x%lx, grain %d, row %d, "
699                         "labels \"%s\": %s\n", page_frame_number,
700                         offset_in_page, mci->csrows[row].grain, row, labels,
701                         msg);
702
703         if (edac_get_panic_on_ue())
704                 panic("EDAC MC%d: UE page 0x%lx, offset 0x%lx, grain %d, "
705                         "row %d, labels \"%s\": %s\n", mci->mc_idx,
706                         page_frame_number, offset_in_page,
707                         mci->csrows[row].grain, row, labels, msg);
708
709         mci->ue_count++;
710         mci->csrows[row].ue_count++;
711 }
712 EXPORT_SYMBOL_GPL(edac_mc_handle_ue);
713
714 void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci, const char *msg)
715 {
716         if (edac_get_panic_on_ue())
717                 panic("EDAC MC%d: Uncorrected Error", mci->mc_idx);
718
719         if (edac_get_log_ue())
720                 edac_mc_printk(mci, KERN_WARNING,
721                         "UE - no information available: %s\n", msg);
722         mci->ue_noinfo_count++;
723         mci->ue_count++;
724 }
725 EXPORT_SYMBOL_GPL(edac_mc_handle_ue_no_info);
726
727
728 /*************************************************************
729  * On Fully Buffered DIMM modules, this help function is
730  * called to process UE events
731  */
732 void edac_mc_handle_fbd_ue(struct mem_ctl_info *mci,
733                                 unsigned int csrow,
734                                 unsigned int channela,
735                                 unsigned int channelb,
736                                 char *msg)
737 {
738         int len = EDAC_MC_LABEL_LEN * 4;
739         char labels[len + 1];
740         char *pos = labels;
741         int chars;
742
743         if (csrow >= mci->nr_csrows) {
744                 /* something is wrong */
745                 edac_mc_printk(mci, KERN_ERR,
746                         "INTERNAL ERROR: row out of range (%d >= %d)\n",
747                         csrow, mci->nr_csrows);
748                 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
749                 return;
750         }
751
752         if (channela >= mci->csrows[csrow].nr_channels) {
753                 /* something is wrong */
754                 edac_mc_printk(mci, KERN_ERR,
755                         "INTERNAL ERROR: channel-a out of range "
756                         "(%d >= %d)\n",
757                         channela, mci->csrows[csrow].nr_channels);
758                 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
759                 return;
760         }
761
762         if (channelb >= mci->csrows[csrow].nr_channels) {
763                 /* something is wrong */
764                 edac_mc_printk(mci, KERN_ERR,
765                         "INTERNAL ERROR: channel-b out of range "
766                         "(%d >= %d)\n",
767                         channelb, mci->csrows[csrow].nr_channels);
768                 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
769                 return;
770         }
771
772         mci->ue_count++;
773         mci->csrows[csrow].ue_count++;
774
775         /* Generate the DIMM labels from the specified channels */
776         chars = snprintf(pos, len + 1, "%s",
777                          mci->csrows[csrow].channels[channela].label);
778         len -= chars; pos += chars;
779         chars = snprintf(pos, len + 1, "-%s",
780                          mci->csrows[csrow].channels[channelb].label);
781
782         if (edac_get_log_ue())
783                 edac_mc_printk(mci, KERN_EMERG,
784                         "UE row %d, channel-a= %d channel-b= %d "
785                         "labels \"%s\": %s\n", csrow, channela, channelb,
786                         labels, msg);
787
788         if (edac_get_panic_on_ue())
789                 panic("UE row %d, channel-a= %d channel-b= %d "
790                                 "labels \"%s\": %s\n", csrow, channela,
791                                 channelb, labels, msg);
792 }
793 EXPORT_SYMBOL(edac_mc_handle_fbd_ue);
794
795 /*************************************************************
796  * On Fully Buffered DIMM modules, this help function is
797  * called to process CE events
798  */
799 void edac_mc_handle_fbd_ce(struct mem_ctl_info *mci,
800                            unsigned int csrow,
801                            unsigned int channel,
802                            char *msg)
803 {
804
805         /* Ensure boundary values */
806         if (csrow >= mci->nr_csrows) {
807                 /* something is wrong */
808                 edac_mc_printk(mci, KERN_ERR,
809                         "INTERNAL ERROR: row out of range (%d >= %d)\n",
810                         csrow, mci->nr_csrows);
811                 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
812                 return;
813         }
814         if (channel >= mci->csrows[csrow].nr_channels) {
815                 /* something is wrong */
816                 edac_mc_printk(mci, KERN_ERR,
817                         "INTERNAL ERROR: channel out of range (%d >= %d)\n",
818                         channel, mci->csrows[csrow].nr_channels);
819                 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
820                 return;
821         }
822
823         if (edac_get_log_ce())
824                 /* FIXME - put in DIMM location */
825                 edac_mc_printk(mci, KERN_WARNING,
826                         "CE row %d, channel %d, label \"%s\": %s\n",
827                         csrow, channel,
828                         mci->csrows[csrow].channels[channel].label,
829                         msg);
830
831         mci->ce_count++;
832         mci->csrows[csrow].ce_count++;
833         mci->csrows[csrow].channels[channel].ce_count++;
834 }
835 EXPORT_SYMBOL(edac_mc_handle_fbd_ce);
836
837
838 /*
839  * Iterate over all MC instances and check for ECC, et al, errors
840  */
841 void edac_check_mc_devices(void)
842 {
843         struct list_head *item;
844         struct mem_ctl_info *mci;
845
846         debugf3("%s()\n", __func__);
847         mutex_lock(&mem_ctls_mutex);
848
849         list_for_each(item, &mc_devices) {
850                 mci = list_entry(item, struct mem_ctl_info, link);
851
852                 if (mci->edac_check != NULL)
853                         mci->edac_check(mci);
854         }
855
856         mutex_unlock(&mem_ctls_mutex);
857 }