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