blob: eae1ca1caebdffab48d1ad68b300e2c6a6adb3a0 [file] [log] [blame]
Alan Coxda9bb1d2006-01-18 17:44:13 -08001/*
2 * edac_mc kernel module
Doug Thompson49c0dab72006-07-10 04:45:19 -07003 * (C) 2005, 2006 Linux Networx (http://lnxi.com)
Alan Coxda9bb1d2006-01-18 17:44:13 -08004 * 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
Alan Coxda9bb1d2006-01-18 17:44:13 -080015#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>
Alan Coxda9bb1d2006-01-18 17:44:13 -080030#include <asm/uaccess.h>
31#include <asm/page.h>
32#include <asm/edac.h>
Alan Coxda9bb1d2006-01-18 17:44:13 -080033#include "edac_mc.h"
Douglas Thompson7c9281d2007-07-19 01:49:33 -070034#include "edac_module.h"
Alan Coxda9bb1d2006-01-18 17:44:13 -080035
Alan Coxda9bb1d2006-01-18 17:44:13 -080036
Alan Coxda9bb1d2006-01-18 17:44:13 -080037/* lock to memory controller's control array */
Matthias Kaehlcke63b7df92007-07-19 01:49:38 -070038static DEFINE_MUTEX(mem_ctls_mutex);
Alan Coxda9bb1d2006-01-18 17:44:13 -080039static struct list_head mc_devices = LIST_HEAD_INIT(mc_devices);
40
Alan Coxda9bb1d2006-01-18 17:44:13 -080041#ifdef CONFIG_EDAC_DEBUG
42
Adrian Bunk2da1c112007-07-19 01:49:32 -070043static void edac_mc_dump_channel(struct channel_info *chan)
Alan Coxda9bb1d2006-01-18 17:44:13 -080044{
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
Adrian Bunk2da1c112007-07-19 01:49:32 -070052static void edac_mc_dump_csrow(struct csrow_info *csrow)
Alan Coxda9bb1d2006-01-18 17:44:13 -080053{
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
Adrian Bunk2da1c112007-07-19 01:49:32 -070067static void edac_mc_dump_mci(struct mem_ctl_info *mci)
Alan Coxda9bb1d2006-01-18 17:44:13 -080068{
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);
Doug Thompson37f04582006-06-30 01:56:07 -070076 debugf3("\tdev = %p\n", mci->dev);
Alan Coxda9bb1d2006-01-18 17:44:13 -080077 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
Dave Petersone7ecd892006-03-26 01:38:52 -080082#endif /* CONFIG_EDAC_DEBUG */
Alan Coxda9bb1d2006-01-18 17:44:13 -080083
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 */
Douglas Thompsone27e3da2007-07-19 01:49:36 -070091char * edac_align_ptr(void *ptr, unsigned size)
Alan Coxda9bb1d2006-01-18 17:44:13 -080092{
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
Alan Coxda9bb1d2006-01-18 17:44:13 -0800118/**
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,
Dave Petersone7ecd892006-03-26 01:38:52 -0800135 unsigned nr_chans)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800136{
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;
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700150 csi = (struct csrow_info *)edac_align_ptr(&mci[1], sizeof(*csi));
Alan Coxda9bb1d2006-01-18 17:44:13 -0800151 chi = (struct channel_info *)
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700152 edac_align_ptr(&csi[nr_csrows], sizeof(*chi));
153 pvt = edac_align_ptr(&chi[nr_chans * nr_csrows], sz_pvt);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800154 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
Dave Petersone7ecd892006-03-26 01:38:52 -0800166 memset(mci, 0, size); /* clear all fields */
Alan Coxda9bb1d2006-01-18 17:44:13 -0800167 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}
Dave Peterson91105402006-03-26 01:38:55 -0800188EXPORT_SYMBOL_GPL(edac_mc_alloc);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800189
Alan Coxda9bb1d2006-01-18 17:44:13 -0800190/**
191 * edac_mc_free: Free a previously allocated 'mci' structure
192 * @mci: pointer to a struct mem_ctl_info structure
Alan Coxda9bb1d2006-01-18 17:44:13 -0800193 */
194void edac_mc_free(struct mem_ctl_info *mci)
195{
Dave Peterson472678e2006-03-26 01:38:49 -0800196 kfree(mci);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800197}
Dave Peterson91105402006-03-26 01:38:55 -0800198EXPORT_SYMBOL_GPL(edac_mc_free);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800199
Doug Thompson37f04582006-06-30 01:56:07 -0700200static struct mem_ctl_info *find_mci_by_dev(struct device *dev)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800201{
202 struct mem_ctl_info *mci;
203 struct list_head *item;
204
Dave Peterson537fba22006-03-26 01:38:40 -0800205 debugf3("%s()\n", __func__);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800206
207 list_for_each(item, &mc_devices) {
208 mci = list_entry(item, struct mem_ctl_info, link);
209
Doug Thompson37f04582006-06-30 01:56:07 -0700210 if (mci->dev == dev)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800211 return mci;
212 }
213
214 return NULL;
215}
216
Doug Thompson2d7bbb92006-06-30 01:56:08 -0700217/* 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)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800222{
223 struct list_head *item, *insert_before;
224 struct mem_ctl_info *p;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800225
Doug Thompson2d7bbb92006-06-30 01:56:08 -0700226 insert_before = &mc_devices;
227
228 if (unlikely((p = find_mci_by_dev(mci->dev)) != NULL))
229 goto fail0;
230
231 list_for_each(item, &mc_devices) {
232 p = list_entry(item, struct mem_ctl_info, link);
233
234 if (p->mc_idx >= mci->mc_idx) {
235 if (unlikely(p->mc_idx == mci->mc_idx))
236 goto fail1;
237
238 insert_before = item;
239 break;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800240 }
Alan Coxda9bb1d2006-01-18 17:44:13 -0800241 }
242
243 list_add_tail_rcu(&mci->link, insert_before);
244 return 0;
Doug Thompson2d7bbb92006-06-30 01:56:08 -0700245
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;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800257}
258
Dave Petersone7ecd892006-03-26 01:38:52 -0800259static void complete_mc_list_del(struct rcu_head *head)
Dave Petersona1d03fc2006-03-26 01:38:46 -0800260{
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
Dave Petersone7ecd892006-03-26 01:38:52 -0800268static void del_mc_from_global_list(struct mem_ctl_info *mci)
Dave Petersona1d03fc2006-03-26 01:38:46 -0800269{
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
Alan Coxda9bb1d2006-01-18 17:44:13 -0800276/**
Douglas Thompson5da08312007-07-19 01:49:31 -0700277 * 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
304/**
Dave Peterson472678e2006-03-26 01:38:49 -0800305 * edac_mc_add_mc: Insert the 'mci' structure into the mci global list and
306 * create sysfs entries associated with mci structure
Alan Coxda9bb1d2006-01-18 17:44:13 -0800307 * @mci: pointer to the mci structure to be added to the list
Doug Thompson2d7bbb92006-06-30 01:56:08 -0700308 * @mc_idx: A unique numeric identifier to be assigned to the 'mci' structure.
Alan Coxda9bb1d2006-01-18 17:44:13 -0800309 *
310 * Return:
311 * 0 Success
312 * !0 Failure
313 */
314
315/* FIXME - should a warning be printed if no error detection? correction? */
Doug Thompson2d7bbb92006-06-30 01:56:08 -0700316int edac_mc_add_mc(struct mem_ctl_info *mci, int mc_idx)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800317{
Dave Peterson537fba22006-03-26 01:38:40 -0800318 debugf0("%s()\n", __func__);
Doug Thompson2d7bbb92006-06-30 01:56:08 -0700319 mci->mc_idx = mc_idx;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800320#ifdef CONFIG_EDAC_DEBUG
321 if (edac_debug_level >= 3)
322 edac_mc_dump_mci(mci);
Dave Petersone7ecd892006-03-26 01:38:52 -0800323
Alan Coxda9bb1d2006-01-18 17:44:13 -0800324 if (edac_debug_level >= 4) {
325 int i;
326
327 for (i = 0; i < mci->nr_csrows; i++) {
328 int j;
Dave Petersone7ecd892006-03-26 01:38:52 -0800329
Alan Coxda9bb1d2006-01-18 17:44:13 -0800330 edac_mc_dump_csrow(&mci->csrows[i]);
331 for (j = 0; j < mci->csrows[i].nr_channels; j++)
Dave Petersone7ecd892006-03-26 01:38:52 -0800332 edac_mc_dump_channel(
333 &mci->csrows[i].channels[j]);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800334 }
335 }
336#endif
Matthias Kaehlcke63b7df92007-07-19 01:49:38 -0700337 mutex_lock(&mem_ctls_mutex);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800338
339 if (add_mc_to_global_list(mci))
Dave Peterson028a7b62006-03-26 01:38:47 -0800340 goto fail0;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800341
342 /* set load time so that error rate can be tracked */
343 mci->start_time = jiffies;
344
eric wollesen9794f332007-02-12 00:53:08 -0800345 if (edac_create_sysfs_mci_device(mci)) {
346 edac_mc_printk(mci, KERN_WARNING,
Dave Peterson537fba22006-03-26 01:38:40 -0800347 "failed to create sysfs device\n");
eric wollesen9794f332007-02-12 00:53:08 -0800348 goto fail1;
349 }
Alan Coxda9bb1d2006-01-18 17:44:13 -0800350
351 /* Report action taken */
Doug Thompson37f04582006-06-30 01:56:07 -0700352 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));
Alan Coxda9bb1d2006-01-18 17:44:13 -0800354
Matthias Kaehlcke63b7df92007-07-19 01:49:38 -0700355 mutex_unlock(&mem_ctls_mutex);
Dave Peterson028a7b62006-03-26 01:38:47 -0800356 return 0;
357
358fail1:
359 del_mc_from_global_list(mci);
360
361fail0:
Matthias Kaehlcke63b7df92007-07-19 01:49:38 -0700362 mutex_unlock(&mem_ctls_mutex);
Dave Peterson028a7b62006-03-26 01:38:47 -0800363 return 1;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800364}
Dave Peterson91105402006-03-26 01:38:55 -0800365EXPORT_SYMBOL_GPL(edac_mc_add_mc);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800366
Alan Coxda9bb1d2006-01-18 17:44:13 -0800367/**
Dave Peterson472678e2006-03-26 01:38:49 -0800368 * edac_mc_del_mc: Remove sysfs entries for specified mci structure and
369 * remove mci structure from global list
Doug Thompson37f04582006-06-30 01:56:07 -0700370 * @pdev: Pointer to 'struct device' representing mci structure to remove.
Alan Coxda9bb1d2006-01-18 17:44:13 -0800371 *
Dave Peterson18dbc332006-03-26 01:38:50 -0800372 * Return pointer to removed mci structure, or NULL if device not found.
Alan Coxda9bb1d2006-01-18 17:44:13 -0800373 */
Doug Thompson37f04582006-06-30 01:56:07 -0700374struct mem_ctl_info * edac_mc_del_mc(struct device *dev)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800375{
Dave Peterson18dbc332006-03-26 01:38:50 -0800376 struct mem_ctl_info *mci;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800377
Dave Peterson18dbc332006-03-26 01:38:50 -0800378 debugf0("MC: %s()\n", __func__);
Matthias Kaehlcke63b7df92007-07-19 01:49:38 -0700379 mutex_lock(&mem_ctls_mutex);
Dave Peterson18dbc332006-03-26 01:38:50 -0800380
Doug Thompson37f04582006-06-30 01:56:07 -0700381 if ((mci = find_mci_by_dev(dev)) == NULL) {
Matthias Kaehlcke63b7df92007-07-19 01:49:38 -0700382 mutex_unlock(&mem_ctls_mutex);
Dave Peterson18dbc332006-03-26 01:38:50 -0800383 return NULL;
384 }
385
386 edac_remove_sysfs_mci_device(mci);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800387 del_mc_from_global_list(mci);
Matthias Kaehlcke63b7df92007-07-19 01:49:38 -0700388 mutex_unlock(&mem_ctls_mutex);
Dave Peterson537fba22006-03-26 01:38:40 -0800389 edac_printk(KERN_INFO, EDAC_MC,
Doug Thompson37f04582006-06-30 01:56:07 -0700390 "Removed device %d for %s %s: DEV %s\n", mci->mc_idx,
391 mci->mod_name, mci->ctl_name, dev_name(mci->dev));
Dave Peterson18dbc332006-03-26 01:38:50 -0800392 return mci;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800393}
Dave Peterson91105402006-03-26 01:38:55 -0800394EXPORT_SYMBOL_GPL(edac_mc_del_mc);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800395
Adrian Bunk2da1c112007-07-19 01:49:32 -0700396static void edac_mc_scrub_block(unsigned long page, unsigned long offset,
397 u32 size)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800398{
399 struct page *pg;
400 void *virt_addr;
401 unsigned long flags = 0;
402
Dave Peterson537fba22006-03-26 01:38:40 -0800403 debugf3("%s()\n", __func__);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800404
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
Alan Coxda9bb1d2006-01-18 17:44:13 -0800427/* FIXME - should return -1 */
Dave Petersone7ecd892006-03-26 01:38:52 -0800428int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci, unsigned long page)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800429{
430 struct csrow_info *csrows = mci->csrows;
431 int row, i;
432
Dave Peterson537fba22006-03-26 01:38:40 -0800433 debugf1("MC%d: %s(): 0x%lx\n", mci->mc_idx, __func__, page);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800434 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
Dave Peterson537fba22006-03-26 01:38:40 -0800442 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);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800446
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)
Dave Peterson537fba22006-03-26 01:38:40 -0800457 edac_mc_printk(mci, KERN_ERR,
458 "could not look up page error address %lx\n",
459 (unsigned long) page);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800460
461 return row;
462}
Dave Peterson91105402006-03-26 01:38:55 -0800463EXPORT_SYMBOL_GPL(edac_mc_find_csrow_by_page);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800464
Alan Coxda9bb1d2006-01-18 17:44:13 -0800465/* 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,
Dave Petersone7ecd892006-03-26 01:38:52 -0800468 unsigned long page_frame_number, unsigned long offset_in_page,
469 unsigned long syndrome, int row, int channel, const char *msg)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800470{
471 unsigned long remapped_page;
472
Dave Peterson537fba22006-03-26 01:38:40 -0800473 debugf3("MC%d: %s()\n", mci->mc_idx, __func__);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800474
475 /* FIXME - maybe make panic on INTERNAL ERROR an option */
476 if (row >= mci->nr_csrows || row < 0) {
477 /* something is wrong */
Dave Peterson537fba22006-03-26 01:38:40 -0800478 edac_mc_printk(mci, KERN_ERR,
479 "INTERNAL ERROR: row out of range "
480 "(%d >= %d)\n", row, mci->nr_csrows);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800481 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
482 return;
483 }
Dave Petersone7ecd892006-03-26 01:38:52 -0800484
Alan Coxda9bb1d2006-01-18 17:44:13 -0800485 if (channel >= mci->csrows[row].nr_channels || channel < 0) {
486 /* something is wrong */
Dave Peterson537fba22006-03-26 01:38:40 -0800487 edac_mc_printk(mci, KERN_ERR,
488 "INTERNAL ERROR: channel out of range "
489 "(%d >= %d)\n", channel,
490 mci->csrows[row].nr_channels);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800491 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
492 return;
493 }
494
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700495 if (edac_get_log_ce())
Alan Coxda9bb1d2006-01-18 17:44:13 -0800496 /* FIXME - put in DIMM location */
Dave Peterson537fba22006-03-26 01:38:40 -0800497 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);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800503
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,
Dave Petersone7ecd892006-03-26 01:38:52 -0800523 mci->csrows[row].grain);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800524 }
525}
Dave Peterson91105402006-03-26 01:38:55 -0800526EXPORT_SYMBOL_GPL(edac_mc_handle_ce);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800527
Dave Petersone7ecd892006-03-26 01:38:52 -0800528void edac_mc_handle_ce_no_info(struct mem_ctl_info *mci, const char *msg)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800529{
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700530 if (edac_get_log_ce())
Dave Peterson537fba22006-03-26 01:38:40 -0800531 edac_mc_printk(mci, KERN_WARNING,
532 "CE - no information available: %s\n", msg);
Dave Petersone7ecd892006-03-26 01:38:52 -0800533
Alan Coxda9bb1d2006-01-18 17:44:13 -0800534 mci->ce_noinfo_count++;
535 mci->ce_count++;
536}
Dave Peterson91105402006-03-26 01:38:55 -0800537EXPORT_SYMBOL_GPL(edac_mc_handle_ce_no_info);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800538
Alan Coxda9bb1d2006-01-18 17:44:13 -0800539void edac_mc_handle_ue(struct mem_ctl_info *mci,
Dave Petersone7ecd892006-03-26 01:38:52 -0800540 unsigned long page_frame_number, unsigned long offset_in_page,
541 int row, const char *msg)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800542{
543 int len = EDAC_MC_LABEL_LEN * 4;
544 char labels[len + 1];
545 char *pos = labels;
546 int chan;
547 int chars;
548
Dave Peterson537fba22006-03-26 01:38:40 -0800549 debugf3("MC%d: %s()\n", mci->mc_idx, __func__);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800550
551 /* FIXME - maybe make panic on INTERNAL ERROR an option */
552 if (row >= mci->nr_csrows || row < 0) {
553 /* something is wrong */
Dave Peterson537fba22006-03-26 01:38:40 -0800554 edac_mc_printk(mci, KERN_ERR,
555 "INTERNAL ERROR: row out of range "
556 "(%d >= %d)\n", row, mci->nr_csrows);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800557 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
558 return;
559 }
560
561 chars = snprintf(pos, len + 1, "%s",
Dave Petersone7ecd892006-03-26 01:38:52 -0800562 mci->csrows[row].channels[0].label);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800563 len -= chars;
564 pos += chars;
Dave Petersone7ecd892006-03-26 01:38:52 -0800565
Alan Coxda9bb1d2006-01-18 17:44:13 -0800566 for (chan = 1; (chan < mci->csrows[row].nr_channels) && (len > 0);
567 chan++) {
568 chars = snprintf(pos, len + 1, ":%s",
Dave Petersone7ecd892006-03-26 01:38:52 -0800569 mci->csrows[row].channels[chan].label);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800570 len -= chars;
571 pos += chars;
572 }
573
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700574 if (edac_get_log_ue())
Dave Peterson537fba22006-03-26 01:38:40 -0800575 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);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800580
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700581 if (edac_get_panic_on_ue())
Dave Petersone7ecd892006-03-26 01:38:52 -0800582 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);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800586
587 mci->ue_count++;
588 mci->csrows[row].ue_count++;
589}
Dave Peterson91105402006-03-26 01:38:55 -0800590EXPORT_SYMBOL_GPL(edac_mc_handle_ue);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800591
Dave Petersone7ecd892006-03-26 01:38:52 -0800592void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci, const char *msg)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800593{
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700594 if (edac_get_panic_on_ue())
Alan Coxda9bb1d2006-01-18 17:44:13 -0800595 panic("EDAC MC%d: Uncorrected Error", mci->mc_idx);
596
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700597 if (edac_get_log_ue())
Dave Peterson537fba22006-03-26 01:38:40 -0800598 edac_mc_printk(mci, KERN_WARNING,
599 "UE - no information available: %s\n", msg);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800600 mci->ue_noinfo_count++;
601 mci->ue_count++;
602}
Dave Peterson91105402006-03-26 01:38:55 -0800603EXPORT_SYMBOL_GPL(edac_mc_handle_ue_no_info);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800604
Alan Coxda9bb1d2006-01-18 17:44:13 -0800605
eric wollesen9794f332007-02-12 00:53:08 -0800606/*************************************************************
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
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700660 if (edac_get_log_ue())
eric wollesen9794f332007-02-12 00:53:08 -0800661 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
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700666 if (edac_get_panic_on_ue())
eric wollesen9794f332007-02-12 00:53:08 -0800667 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
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700701 if (edac_get_log_ce())
eric wollesen9794f332007-02-12 00:53:08 -0800702 /* 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
Alan Coxda9bb1d2006-01-18 17:44:13 -0800716/*
717 * Iterate over all MC instances and check for ECC, et al, errors
718 */
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700719void edac_check_mc_devices(void)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800720{
Alan Coxda9bb1d2006-01-18 17:44:13 -0800721 struct list_head *item;
722 struct mem_ctl_info *mci;
723
Dave Peterson537fba22006-03-26 01:38:40 -0800724 debugf3("%s()\n", __func__);
Matthias Kaehlcke63b7df92007-07-19 01:49:38 -0700725 mutex_lock(&mem_ctls_mutex);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800726
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
Matthias Kaehlcke63b7df92007-07-19 01:49:38 -0700734 mutex_unlock(&mem_ctls_mutex);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800735}