drivers/edac: mod PCI poll names
[sfrench/cifs-2.6.git] / 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 old_state;
226
227         if(edac_op_state == EDAC_OPSTATE_POLL)
228                 return 1;
229
230         old_state = edac_err_assert;
231         edac_err_assert = 0;
232
233         return old_state;
234 }
235
236 /*
237  * edac_mc_workq_function
238  *      performs the operation scheduled by a workq request
239  */
240 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
241 static void edac_mc_workq_function(struct work_struct *work_req)
242 {
243         struct delayed_work *d_work = (struct delayed_work*) work_req;
244         struct mem_ctl_info *mci = to_edac_mem_ctl_work(d_work);
245 #else
246 static void edac_mc_workq_function(void *ptr)
247 {
248         struct mem_ctl_info *mci = (struct mem_ctl_info *) ptr;
249 #endif
250
251         mutex_lock(&mem_ctls_mutex);
252
253         /* Only poll controllers that are running polled and have a check */
254         if (edac_mc_assert_error_check_and_clear() && (mci->edac_check != NULL))
255                 mci->edac_check(mci);
256
257         /*
258          * FIXME: temp place holder for PCI checks,
259          * goes away when we break out PCI
260          */
261         edac_pci_do_parity_check();
262
263         mutex_unlock(&mem_ctls_mutex);
264
265         /* Reschedule */
266         queue_delayed_work(edac_workqueue, &mci->work,
267                         msecs_to_jiffies(edac_mc_get_poll_msec()));
268 }
269
270 /*
271  * edac_mc_workq_setup
272  *      initialize a workq item for this mci
273  *      passing in the new delay period in msec
274  */
275 void edac_mc_workq_setup(struct mem_ctl_info *mci, unsigned msec)
276 {
277         debugf0("%s()\n", __func__);
278
279 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
280         INIT_DELAYED_WORK(&mci->work, edac_mc_workq_function);
281 #else
282         INIT_WORK(&mci->work, edac_mc_workq_function, mci);
283 #endif
284         queue_delayed_work(edac_workqueue, &mci->work, msecs_to_jiffies(msec));
285 }
286
287 /*
288  * edac_mc_workq_teardown
289  *      stop the workq processing on this mci
290  */
291 void edac_mc_workq_teardown(struct mem_ctl_info *mci)
292 {
293         int status;
294
295         status = cancel_delayed_work(&mci->work);
296         if (status == 0) {
297                 /* workq instance might be running, wait for it */
298                 flush_workqueue(edac_workqueue);
299         }
300 }
301
302 /*
303  * edac_reset_delay_period
304  */
305
306 void edac_reset_delay_period(struct mem_ctl_info *mci, unsigned long value)
307 {
308         mutex_lock(&mem_ctls_mutex);
309
310         /* cancel the current workq request */
311         edac_mc_workq_teardown(mci);
312
313         /* restart the workq request, with new delay value */
314         edac_mc_workq_setup(mci, value);
315
316         mutex_unlock(&mem_ctls_mutex);
317 }
318
319 /* Return 0 on success, 1 on failure.
320  * Before calling this function, caller must
321  * assign a unique value to mci->mc_idx.
322  */
323 static int add_mc_to_global_list (struct mem_ctl_info *mci)
324 {
325         struct list_head *item, *insert_before;
326         struct mem_ctl_info *p;
327
328         insert_before = &mc_devices;
329
330         if (unlikely((p = find_mci_by_dev(mci->dev)) != NULL))
331                 goto fail0;
332
333         list_for_each(item, &mc_devices) {
334                 p = list_entry(item, struct mem_ctl_info, link);
335
336                 if (p->mc_idx >= mci->mc_idx) {
337                         if (unlikely(p->mc_idx == mci->mc_idx))
338                                 goto fail1;
339
340                         insert_before = item;
341                         break;
342                 }
343         }
344
345         list_add_tail_rcu(&mci->link, insert_before);
346         atomic_inc(&edac_handlers);
347         return 0;
348
349 fail0:
350         edac_printk(KERN_WARNING, EDAC_MC,
351                     "%s (%s) %s %s already assigned %d\n", p->dev->bus_id,
352                     dev_name(mci), p->mod_name, p->ctl_name, p->mc_idx);
353         return 1;
354
355 fail1:
356         edac_printk(KERN_WARNING, EDAC_MC,
357                     "bug in low-level driver: attempt to assign\n"
358                     "    duplicate mc_idx %d in %s()\n", p->mc_idx, __func__);
359         return 1;
360 }
361
362 static void complete_mc_list_del(struct rcu_head *head)
363 {
364         struct mem_ctl_info *mci;
365
366         mci = container_of(head, struct mem_ctl_info, rcu);
367         INIT_LIST_HEAD(&mci->link);
368         complete(&mci->complete);
369 }
370
371 static void del_mc_from_global_list(struct mem_ctl_info *mci)
372 {
373         atomic_dec(&edac_handlers);
374         list_del_rcu(&mci->link);
375         init_completion(&mci->complete);
376         call_rcu(&mci->rcu, complete_mc_list_del);
377         wait_for_completion(&mci->complete);
378 }
379
380 /**
381  * edac_mc_find: Search for a mem_ctl_info structure whose index is 'idx'.
382  *
383  * If found, return a pointer to the structure.
384  * Else return NULL.
385  *
386  * Caller must hold mem_ctls_mutex.
387  */
388 struct mem_ctl_info * edac_mc_find(int idx)
389 {
390         struct list_head *item;
391         struct mem_ctl_info *mci;
392
393         list_for_each(item, &mc_devices) {
394                 mci = list_entry(item, struct mem_ctl_info, link);
395
396                 if (mci->mc_idx >= idx) {
397                         if (mci->mc_idx == idx)
398                                 return mci;
399
400                         break;
401                 }
402         }
403
404         return NULL;
405 }
406 EXPORT_SYMBOL(edac_mc_find);
407
408 /**
409  * edac_mc_add_mc: Insert the 'mci' structure into the mci global list and
410  *                 create sysfs entries associated with mci structure
411  * @mci: pointer to the mci structure to be added to the list
412  * @mc_idx: A unique numeric identifier to be assigned to the 'mci' structure.
413  *
414  * Return:
415  *      0       Success
416  *      !0      Failure
417  */
418
419 /* FIXME - should a warning be printed if no error detection? correction? */
420 int edac_mc_add_mc(struct mem_ctl_info *mci, int mc_idx)
421 {
422         debugf0("%s()\n", __func__);
423         mci->mc_idx = mc_idx;
424 #ifdef CONFIG_EDAC_DEBUG
425         if (edac_debug_level >= 3)
426                 edac_mc_dump_mci(mci);
427
428         if (edac_debug_level >= 4) {
429                 int i;
430
431                 for (i = 0; i < mci->nr_csrows; i++) {
432                         int j;
433
434                         edac_mc_dump_csrow(&mci->csrows[i]);
435                         for (j = 0; j < mci->csrows[i].nr_channels; j++)
436                                 edac_mc_dump_channel(
437                                         &mci->csrows[i].channels[j]);
438                 }
439         }
440 #endif
441         mutex_lock(&mem_ctls_mutex);
442
443         if (add_mc_to_global_list(mci))
444                 goto fail0;
445
446         /* set load time so that error rate can be tracked */
447         mci->start_time = jiffies;
448
449         if (edac_create_sysfs_mci_device(mci)) {
450                 edac_mc_printk(mci, KERN_WARNING,
451                         "failed to create sysfs device\n");
452                 goto fail1;
453         }
454
455         /* If there IS a check routine, then we are running POLLED */
456         if (mci->edac_check != NULL) {
457                 /* This instance is NOW RUNNING */
458                 mci->op_state = OP_RUNNING_POLL;
459
460                 edac_mc_workq_setup(mci, edac_mc_get_poll_msec());
461         } else {
462                 mci->op_state = OP_RUNNING_INTERRUPT;
463         }
464
465         /* Report action taken */
466         edac_mc_printk(mci, KERN_INFO, "Giving out device to %s %s: DEV %s\n",
467                 mci->mod_name, mci->ctl_name, dev_name(mci));
468
469         mutex_unlock(&mem_ctls_mutex);
470         return 0;
471
472 fail1:
473         del_mc_from_global_list(mci);
474
475 fail0:
476         mutex_unlock(&mem_ctls_mutex);
477         return 1;
478 }
479 EXPORT_SYMBOL_GPL(edac_mc_add_mc);
480
481 /**
482  * edac_mc_del_mc: Remove sysfs entries for specified mci structure and
483  *                 remove mci structure from global list
484  * @pdev: Pointer to 'struct device' representing mci structure to remove.
485  *
486  * Return pointer to removed mci structure, or NULL if device not found.
487  */
488 struct mem_ctl_info * edac_mc_del_mc(struct device *dev)
489 {
490         struct mem_ctl_info *mci;
491
492         debugf0("MC: %s()\n", __func__);
493         mutex_lock(&mem_ctls_mutex);
494
495         if ((mci = find_mci_by_dev(dev)) == NULL) {
496                 mutex_unlock(&mem_ctls_mutex);
497                 return NULL;
498         }
499
500         /* marking MCI offline */
501         mci->op_state = OP_OFFLINE;
502
503         /* flush workq processes */
504         edac_mc_workq_teardown(mci);
505
506         edac_remove_sysfs_mci_device(mci);
507         del_mc_from_global_list(mci);
508         mutex_unlock(&mem_ctls_mutex);
509         edac_printk(KERN_INFO, EDAC_MC,
510                 "Removed device %d for %s %s: DEV %s\n", mci->mc_idx,
511                 mci->mod_name, mci->ctl_name, dev_name(mci));
512         return mci;
513 }
514 EXPORT_SYMBOL_GPL(edac_mc_del_mc);
515
516 static void edac_mc_scrub_block(unsigned long page, unsigned long offset,
517                                 u32 size)
518 {
519         struct page *pg;
520         void *virt_addr;
521         unsigned long flags = 0;
522
523         debugf3("%s()\n", __func__);
524
525         /* ECC error page was not in our memory. Ignore it. */
526         if(!pfn_valid(page))
527                 return;
528
529         /* Find the actual page structure then map it and fix */
530         pg = pfn_to_page(page);
531
532         if (PageHighMem(pg))
533                 local_irq_save(flags);
534
535         virt_addr = kmap_atomic(pg, KM_BOUNCE_READ);
536
537         /* Perform architecture specific atomic scrub operation */
538         atomic_scrub(virt_addr + offset, size);
539
540         /* Unmap and complete */
541         kunmap_atomic(virt_addr, KM_BOUNCE_READ);
542
543         if (PageHighMem(pg))
544                 local_irq_restore(flags);
545 }
546
547 /* FIXME - should return -1 */
548 int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci, unsigned long page)
549 {
550         struct csrow_info *csrows = mci->csrows;
551         int row, i;
552
553         debugf1("MC%d: %s(): 0x%lx\n", mci->mc_idx, __func__, page);
554         row = -1;
555
556         for (i = 0; i < mci->nr_csrows; i++) {
557                 struct csrow_info *csrow = &csrows[i];
558
559                 if (csrow->nr_pages == 0)
560                         continue;
561
562                 debugf3("MC%d: %s(): first(0x%lx) page(0x%lx) last(0x%lx) "
563                         "mask(0x%lx)\n", mci->mc_idx, __func__,
564                         csrow->first_page, page, csrow->last_page,
565                         csrow->page_mask);
566
567                 if ((page >= csrow->first_page) &&
568                     (page <= csrow->last_page) &&
569                     ((page & csrow->page_mask) ==
570                      (csrow->first_page & csrow->page_mask))) {
571                         row = i;
572                         break;
573                 }
574         }
575
576         if (row == -1)
577                 edac_mc_printk(mci, KERN_ERR,
578                         "could not look up page error address %lx\n",
579                         (unsigned long) page);
580
581         return row;
582 }
583 EXPORT_SYMBOL_GPL(edac_mc_find_csrow_by_page);
584
585 /* FIXME - setable log (warning/emerg) levels */
586 /* FIXME - integrate with evlog: http://evlog.sourceforge.net/ */
587 void edac_mc_handle_ce(struct mem_ctl_info *mci,
588                 unsigned long page_frame_number, unsigned long offset_in_page,
589                 unsigned long syndrome, int row, int channel, const char *msg)
590 {
591         unsigned long remapped_page;
592
593         debugf3("MC%d: %s()\n", mci->mc_idx, __func__);
594
595         /* FIXME - maybe make panic on INTERNAL ERROR an option */
596         if (row >= mci->nr_csrows || row < 0) {
597                 /* something is wrong */
598                 edac_mc_printk(mci, KERN_ERR,
599                         "INTERNAL ERROR: row out of range "
600                         "(%d >= %d)\n", row, mci->nr_csrows);
601                 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
602                 return;
603         }
604
605         if (channel >= mci->csrows[row].nr_channels || channel < 0) {
606                 /* something is wrong */
607                 edac_mc_printk(mci, KERN_ERR,
608                         "INTERNAL ERROR: channel out of range "
609                         "(%d >= %d)\n", channel,
610                         mci->csrows[row].nr_channels);
611                 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
612                 return;
613         }
614
615         if (edac_mc_get_log_ce())
616                 /* FIXME - put in DIMM location */
617                 edac_mc_printk(mci, KERN_WARNING,
618                         "CE page 0x%lx, offset 0x%lx, grain %d, syndrome "
619                         "0x%lx, row %d, channel %d, label \"%s\": %s\n",
620                         page_frame_number, offset_in_page,
621                         mci->csrows[row].grain, syndrome, row, channel,
622                         mci->csrows[row].channels[channel].label, msg);
623
624         mci->ce_count++;
625         mci->csrows[row].ce_count++;
626         mci->csrows[row].channels[channel].ce_count++;
627
628         if (mci->scrub_mode & SCRUB_SW_SRC) {
629                 /*
630                  * Some MC's can remap memory so that it is still available
631                  * at a different address when PCI devices map into memory.
632                  * MC's that can't do this lose the memory where PCI devices
633                  * are mapped.  This mapping is MC dependant and so we call
634                  * back into the MC driver for it to map the MC page to
635                  * a physical (CPU) page which can then be mapped to a virtual
636                  * page - which can then be scrubbed.
637                  */
638                 remapped_page = mci->ctl_page_to_phys ?
639                     mci->ctl_page_to_phys(mci, page_frame_number) :
640                     page_frame_number;
641
642                 edac_mc_scrub_block(remapped_page, offset_in_page,
643                                         mci->csrows[row].grain);
644         }
645 }
646 EXPORT_SYMBOL_GPL(edac_mc_handle_ce);
647
648 void edac_mc_handle_ce_no_info(struct mem_ctl_info *mci, const char *msg)
649 {
650         if (edac_mc_get_log_ce())
651                 edac_mc_printk(mci, KERN_WARNING,
652                         "CE - no information available: %s\n", msg);
653
654         mci->ce_noinfo_count++;
655         mci->ce_count++;
656 }
657 EXPORT_SYMBOL_GPL(edac_mc_handle_ce_no_info);
658
659 void edac_mc_handle_ue(struct mem_ctl_info *mci,
660                 unsigned long page_frame_number, unsigned long offset_in_page,
661                 int row, const char *msg)
662 {
663         int len = EDAC_MC_LABEL_LEN * 4;
664         char labels[len + 1];
665         char *pos = labels;
666         int chan;
667         int chars;
668
669         debugf3("MC%d: %s()\n", mci->mc_idx, __func__);
670
671         /* FIXME - maybe make panic on INTERNAL ERROR an option */
672         if (row >= mci->nr_csrows || row < 0) {
673                 /* something is wrong */
674                 edac_mc_printk(mci, KERN_ERR,
675                         "INTERNAL ERROR: row out of range "
676                         "(%d >= %d)\n", row, mci->nr_csrows);
677                 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
678                 return;
679         }
680
681         chars = snprintf(pos, len + 1, "%s",
682                         mci->csrows[row].channels[0].label);
683         len -= chars;
684         pos += chars;
685
686         for (chan = 1; (chan < mci->csrows[row].nr_channels) && (len > 0);
687              chan++) {
688                 chars = snprintf(pos, len + 1, ":%s",
689                                 mci->csrows[row].channels[chan].label);
690                 len -= chars;
691                 pos += chars;
692         }
693
694         if (edac_mc_get_log_ue())
695                 edac_mc_printk(mci, KERN_EMERG,
696                         "UE page 0x%lx, offset 0x%lx, grain %d, row %d, "
697                         "labels \"%s\": %s\n", page_frame_number,
698                         offset_in_page, mci->csrows[row].grain, row, labels,
699                         msg);
700
701         if (edac_mc_get_panic_on_ue())
702                 panic("EDAC MC%d: UE page 0x%lx, offset 0x%lx, grain %d, "
703                         "row %d, labels \"%s\": %s\n", mci->mc_idx,
704                         page_frame_number, offset_in_page,
705                         mci->csrows[row].grain, row, labels, msg);
706
707         mci->ue_count++;
708         mci->csrows[row].ue_count++;
709 }
710 EXPORT_SYMBOL_GPL(edac_mc_handle_ue);
711
712 void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci, const char *msg)
713 {
714         if (edac_mc_get_panic_on_ue())
715                 panic("EDAC MC%d: Uncorrected Error", mci->mc_idx);
716
717         if (edac_mc_get_log_ue())
718                 edac_mc_printk(mci, KERN_WARNING,
719                         "UE - no information available: %s\n", msg);
720         mci->ue_noinfo_count++;
721         mci->ue_count++;
722 }
723 EXPORT_SYMBOL_GPL(edac_mc_handle_ue_no_info);
724
725
726 /*************************************************************
727  * On Fully Buffered DIMM modules, this help function is
728  * called to process UE events
729  */
730 void edac_mc_handle_fbd_ue(struct mem_ctl_info *mci,
731                                 unsigned int csrow,
732                                 unsigned int channela,
733                                 unsigned int channelb,
734                                 char *msg)
735 {
736         int len = EDAC_MC_LABEL_LEN * 4;
737         char labels[len + 1];
738         char *pos = labels;
739         int chars;
740
741         if (csrow >= mci->nr_csrows) {
742                 /* something is wrong */
743                 edac_mc_printk(mci, KERN_ERR,
744                         "INTERNAL ERROR: row out of range (%d >= %d)\n",
745                         csrow, mci->nr_csrows);
746                 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
747                 return;
748         }
749
750         if (channela >= mci->csrows[csrow].nr_channels) {
751                 /* something is wrong */
752                 edac_mc_printk(mci, KERN_ERR,
753                         "INTERNAL ERROR: channel-a out of range "
754                         "(%d >= %d)\n",
755                         channela, mci->csrows[csrow].nr_channels);
756                 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
757                 return;
758         }
759
760         if (channelb >= mci->csrows[csrow].nr_channels) {
761                 /* something is wrong */
762                 edac_mc_printk(mci, KERN_ERR,
763                         "INTERNAL ERROR: channel-b out of range "
764                         "(%d >= %d)\n",
765                         channelb, mci->csrows[csrow].nr_channels);
766                 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
767                 return;
768         }
769
770         mci->ue_count++;
771         mci->csrows[csrow].ue_count++;
772
773         /* Generate the DIMM labels from the specified channels */
774         chars = snprintf(pos, len + 1, "%s",
775                          mci->csrows[csrow].channels[channela].label);
776         len -= chars; pos += chars;
777         chars = snprintf(pos, len + 1, "-%s",
778                          mci->csrows[csrow].channels[channelb].label);
779
780         if (edac_mc_get_log_ue())
781                 edac_mc_printk(mci, KERN_EMERG,
782                         "UE row %d, channel-a= %d channel-b= %d "
783                         "labels \"%s\": %s\n", csrow, channela, channelb,
784                         labels, msg);
785
786         if (edac_mc_get_panic_on_ue())
787                 panic("UE row %d, channel-a= %d channel-b= %d "
788                                 "labels \"%s\": %s\n", csrow, channela,
789                                 channelb, labels, msg);
790 }
791 EXPORT_SYMBOL(edac_mc_handle_fbd_ue);
792
793 /*************************************************************
794  * On Fully Buffered DIMM modules, this help function is
795  * called to process CE events
796  */
797 void edac_mc_handle_fbd_ce(struct mem_ctl_info *mci,
798                            unsigned int csrow,
799                            unsigned int channel,
800                            char *msg)
801 {
802
803         /* Ensure boundary values */
804         if (csrow >= mci->nr_csrows) {
805                 /* something is wrong */
806                 edac_mc_printk(mci, KERN_ERR,
807                         "INTERNAL ERROR: row out of range (%d >= %d)\n",
808                         csrow, mci->nr_csrows);
809                 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
810                 return;
811         }
812         if (channel >= mci->csrows[csrow].nr_channels) {
813                 /* something is wrong */
814                 edac_mc_printk(mci, KERN_ERR,
815                         "INTERNAL ERROR: channel out of range (%d >= %d)\n",
816                         channel, mci->csrows[csrow].nr_channels);
817                 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
818                 return;
819         }
820
821         if (edac_mc_get_log_ce())
822                 /* FIXME - put in DIMM location */
823                 edac_mc_printk(mci, KERN_WARNING,
824                         "CE row %d, channel %d, label \"%s\": %s\n",
825                         csrow, channel,
826                         mci->csrows[csrow].channels[channel].label,
827                         msg);
828
829         mci->ce_count++;
830         mci->csrows[csrow].ce_count++;
831         mci->csrows[csrow].channels[channel].ce_count++;
832 }
833 EXPORT_SYMBOL(edac_mc_handle_fbd_ce);
834
835
836 /*
837  * Iterate over all MC instances and check for ECC, et al, errors
838  */
839 void edac_check_mc_devices(void)
840 {
841         struct list_head *item;
842         struct mem_ctl_info *mci;
843
844         debugf3("%s()\n", __func__);
845         mutex_lock(&mem_ctls_mutex);
846
847         list_for_each(item, &mc_devices) {
848                 mci = list_entry(item, struct mem_ctl_info, link);
849
850                 if (mci->edac_check != NULL)
851                         mci->edac_check(mci);
852         }
853
854         mutex_unlock(&mem_ctls_mutex);
855 }