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> |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 28 | #include <linux/ctype.h> |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 29 | #include <linux/edac.h> |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 30 | #include <linux/bitops.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 | |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 37 | #define CREATE_TRACE_POINTS |
| 38 | #define TRACE_INCLUDE_PATH ../../include/ras |
| 39 | #include <ras/ras_event.h> |
| 40 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 41 | /* lock to memory controller's control array */ |
Matthias Kaehlcke | 63b7df9 | 2007-07-19 01:49:38 -0700 | [diff] [blame] | 42 | static DEFINE_MUTEX(mem_ctls_mutex); |
Robert P. J. Day | ff6ac2a | 2008-04-29 01:03:17 -0700 | [diff] [blame] | 43 | static LIST_HEAD(mc_devices); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 44 | |
Mauro Carvalho Chehab | 6e84d35 | 2012-04-30 10:24:43 -0300 | [diff] [blame] | 45 | unsigned edac_dimm_info_location(struct dimm_info *dimm, char *buf, |
| 46 | unsigned len) |
| 47 | { |
| 48 | struct mem_ctl_info *mci = dimm->mci; |
| 49 | int i, n, count = 0; |
| 50 | char *p = buf; |
| 51 | |
| 52 | for (i = 0; i < mci->n_layers; i++) { |
| 53 | n = snprintf(p, len, "%s %d ", |
| 54 | edac_layer_name[mci->layers[i].type], |
| 55 | dimm->location[i]); |
| 56 | p += n; |
| 57 | len -= n; |
| 58 | count += n; |
| 59 | if (!len) |
| 60 | break; |
| 61 | } |
| 62 | |
| 63 | return count; |
| 64 | } |
| 65 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 66 | #ifdef CONFIG_EDAC_DEBUG |
| 67 | |
Mauro Carvalho Chehab | a4b4be3 | 2012-01-27 10:26:13 -0300 | [diff] [blame] | 68 | static void edac_mc_dump_channel(struct rank_info *chan) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 69 | { |
Mauro Carvalho Chehab | 6e84d35 | 2012-04-30 10:24:43 -0300 | [diff] [blame] | 70 | edac_dbg(4, " channel->chan_idx = %d\n", chan->chan_idx); |
| 71 | edac_dbg(4, " channel = %p\n", chan); |
| 72 | edac_dbg(4, " channel->csrow = %p\n", chan->csrow); |
| 73 | edac_dbg(4, " channel->dimm = %p\n", chan->dimm); |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 74 | } |
| 75 | |
Mauro Carvalho Chehab | 6e84d35 | 2012-04-30 10:24:43 -0300 | [diff] [blame] | 76 | static void edac_mc_dump_dimm(struct dimm_info *dimm, int number) |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 77 | { |
Mauro Carvalho Chehab | 6e84d35 | 2012-04-30 10:24:43 -0300 | [diff] [blame] | 78 | char location[80]; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 79 | |
Mauro Carvalho Chehab | 6e84d35 | 2012-04-30 10:24:43 -0300 | [diff] [blame] | 80 | edac_dimm_info_location(dimm, location, sizeof(location)); |
| 81 | |
| 82 | edac_dbg(4, "%s%i: %smapped as virtual row %d, chan %d\n", |
| 83 | dimm->mci->mem_is_per_rank ? "rank" : "dimm", |
| 84 | number, location, dimm->csrow, dimm->cschannel); |
| 85 | edac_dbg(4, " dimm = %p\n", dimm); |
| 86 | edac_dbg(4, " dimm->label = '%s'\n", dimm->label); |
| 87 | edac_dbg(4, " dimm->nr_pages = 0x%x\n", dimm->nr_pages); |
| 88 | edac_dbg(4, " dimm->grain = %d\n", dimm->grain); |
| 89 | edac_dbg(4, " dimm->nr_pages = 0x%x\n", dimm->nr_pages); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Adrian Bunk | 2da1c11 | 2007-07-19 01:49:32 -0700 | [diff] [blame] | 92 | static void edac_mc_dump_csrow(struct csrow_info *csrow) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 93 | { |
Mauro Carvalho Chehab | 6e84d35 | 2012-04-30 10:24:43 -0300 | [diff] [blame] | 94 | edac_dbg(4, "csrow->csrow_idx = %d\n", csrow->csrow_idx); |
| 95 | edac_dbg(4, " csrow = %p\n", csrow); |
| 96 | edac_dbg(4, " csrow->first_page = 0x%lx\n", csrow->first_page); |
| 97 | edac_dbg(4, " csrow->last_page = 0x%lx\n", csrow->last_page); |
| 98 | edac_dbg(4, " csrow->page_mask = 0x%lx\n", csrow->page_mask); |
| 99 | edac_dbg(4, " csrow->nr_channels = %d\n", csrow->nr_channels); |
| 100 | edac_dbg(4, " csrow->channels = %p\n", csrow->channels); |
| 101 | edac_dbg(4, " csrow->mci = %p\n", csrow->mci); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Adrian Bunk | 2da1c11 | 2007-07-19 01:49:32 -0700 | [diff] [blame] | 104 | static void edac_mc_dump_mci(struct mem_ctl_info *mci) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 105 | { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 106 | edac_dbg(3, "\tmci = %p\n", mci); |
| 107 | edac_dbg(3, "\tmci->mtype_cap = %lx\n", mci->mtype_cap); |
| 108 | edac_dbg(3, "\tmci->edac_ctl_cap = %lx\n", mci->edac_ctl_cap); |
| 109 | edac_dbg(3, "\tmci->edac_cap = %lx\n", mci->edac_cap); |
| 110 | edac_dbg(4, "\tmci->edac_check = %p\n", mci->edac_check); |
| 111 | edac_dbg(3, "\tmci->nr_csrows = %d, csrows = %p\n", |
| 112 | mci->nr_csrows, mci->csrows); |
| 113 | edac_dbg(3, "\tmci->nr_dimms = %d, dimms = %p\n", |
| 114 | mci->tot_dimms, mci->dimms); |
| 115 | edac_dbg(3, "\tdev = %p\n", mci->pdev); |
| 116 | edac_dbg(3, "\tmod_name:ctl_name = %s:%s\n", |
| 117 | mci->mod_name, mci->ctl_name); |
| 118 | edac_dbg(3, "\tpvt_info = %p\n\n", mci->pvt_info); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 121 | #endif /* CONFIG_EDAC_DEBUG */ |
| 122 | |
Borislav Petkov | 239642f | 2009-11-12 15:33:16 +0100 | [diff] [blame] | 123 | /* |
| 124 | * keep those in sync with the enum mem_type |
| 125 | */ |
| 126 | const char *edac_mem_types[] = { |
| 127 | "Empty csrow", |
| 128 | "Reserved csrow type", |
| 129 | "Unknown csrow type", |
| 130 | "Fast page mode RAM", |
| 131 | "Extended data out RAM", |
| 132 | "Burst Extended data out RAM", |
| 133 | "Single data rate SDRAM", |
| 134 | "Registered single data rate SDRAM", |
| 135 | "Double data rate SDRAM", |
| 136 | "Registered Double data rate SDRAM", |
| 137 | "Rambus DRAM", |
| 138 | "Unbuffered DDR2 RAM", |
| 139 | "Fully buffered DDR2", |
| 140 | "Registered DDR2 RAM", |
| 141 | "Rambus XDR", |
| 142 | "Unbuffered DDR3 RAM", |
| 143 | "Registered DDR3 RAM", |
| 144 | }; |
| 145 | EXPORT_SYMBOL_GPL(edac_mem_types); |
| 146 | |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 147 | /** |
| 148 | * edac_align_ptr - Prepares the pointer offsets for a single-shot allocation |
| 149 | * @p: pointer to a pointer with the memory offset to be used. At |
| 150 | * return, this will be incremented to point to the next offset |
| 151 | * @size: Size of the data structure to be reserved |
| 152 | * @n_elems: Number of elements that should be reserved |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 153 | * |
| 154 | * If 'size' is a constant, the compiler will optimize this whole function |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 155 | * down to either a no-op or the addition of a constant to the value of '*p'. |
| 156 | * |
| 157 | * The 'p' pointer is absolutely needed to keep the proper advancing |
| 158 | * further in memory to the proper offsets when allocating the struct along |
| 159 | * with its embedded structs, as edac_device_alloc_ctl_info() does it |
| 160 | * above, for example. |
| 161 | * |
| 162 | * At return, the pointer 'p' will be incremented to be used on a next call |
| 163 | * to this function. |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 164 | */ |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 165 | void *edac_align_ptr(void **p, unsigned size, int n_elems) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 166 | { |
| 167 | unsigned align, r; |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 168 | void *ptr = *p; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 169 | |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 170 | *p += size * n_elems; |
| 171 | |
| 172 | /* |
| 173 | * 'p' can possibly be an unaligned item X such that sizeof(X) is |
| 174 | * 'size'. Adjust 'p' so that its alignment is at least as |
| 175 | * stringent as what the compiler would provide for X and return |
| 176 | * the aligned result. |
| 177 | * Here we assume that the alignment of a "long long" is the most |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 178 | * stringent alignment that the compiler will ever provide by default. |
| 179 | * As far as I know, this is a reasonable assumption. |
| 180 | */ |
| 181 | if (size > sizeof(long)) |
| 182 | align = sizeof(long long); |
| 183 | else if (size > sizeof(int)) |
| 184 | align = sizeof(long); |
| 185 | else if (size > sizeof(short)) |
| 186 | align = sizeof(int); |
| 187 | else if (size > sizeof(char)) |
| 188 | align = sizeof(short); |
| 189 | else |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 190 | return (char *)ptr; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 191 | |
Chris Metcalf | 8447c4d1 | 2012-06-06 13:11:05 -0400 | [diff] [blame] | 192 | r = (unsigned long)p % align; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 193 | |
| 194 | if (r == 0) |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 195 | return (char *)ptr; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 196 | |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 197 | *p += align - r; |
| 198 | |
Douglas Thompson | 7391c6d | 2007-07-19 01:50:21 -0700 | [diff] [blame] | 199 | return (void *)(((unsigned long)ptr) + align - r); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 200 | } |
| 201 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 202 | /** |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 203 | * edac_mc_alloc: Allocate and partially fill a struct mem_ctl_info structure |
| 204 | * @mc_num: Memory controller number |
| 205 | * @n_layers: Number of MC hierarchy layers |
| 206 | * layers: Describes each layer as seen by the Memory Controller |
| 207 | * @size_pvt: size of private storage needed |
| 208 | * |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 209 | * |
| 210 | * Everything is kmalloc'ed as one big chunk - more efficient. |
| 211 | * Only can be used if all structures have the same lifetime - otherwise |
| 212 | * you have to allocate and initialize your own structures. |
| 213 | * |
| 214 | * Use edac_mc_free() to free mc structures allocated by this function. |
| 215 | * |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 216 | * NOTE: drivers handle multi-rank memories in different ways: in some |
| 217 | * drivers, one multi-rank memory stick is mapped as one entry, while, in |
| 218 | * others, a single multi-rank memory stick would be mapped into several |
| 219 | * entries. Currently, this function will allocate multiple struct dimm_info |
| 220 | * on such scenarios, as grouping the multiple ranks require drivers change. |
| 221 | * |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 222 | * Returns: |
Mauro Carvalho Chehab | ca0907b | 2012-05-02 14:37:00 -0300 | [diff] [blame] | 223 | * On failure: NULL |
| 224 | * On success: struct mem_ctl_info pointer |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 225 | */ |
Mauro Carvalho Chehab | ca0907b | 2012-05-02 14:37:00 -0300 | [diff] [blame] | 226 | struct mem_ctl_info *edac_mc_alloc(unsigned mc_num, |
| 227 | unsigned n_layers, |
| 228 | struct edac_mc_layer *layers, |
| 229 | unsigned sz_pvt) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 230 | { |
| 231 | struct mem_ctl_info *mci; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 232 | struct edac_mc_layer *layer; |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 233 | struct csrow_info *csr; |
| 234 | struct rank_info *chan; |
Mauro Carvalho Chehab | a7d7d2e | 2012-01-27 14:12:32 -0300 | [diff] [blame] | 235 | struct dimm_info *dimm; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 236 | u32 *ce_per_layer[EDAC_MAX_LAYERS], *ue_per_layer[EDAC_MAX_LAYERS]; |
| 237 | unsigned pos[EDAC_MAX_LAYERS]; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 238 | unsigned size, tot_dimms = 1, count = 1; |
| 239 | unsigned tot_csrows = 1, tot_channels = 1, tot_errcount = 0; |
Mauro Carvalho Chehab | 5926ff5 | 2012-02-09 11:05:20 -0300 | [diff] [blame] | 240 | void *pvt, *p, *ptr = NULL; |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 241 | int i, j, row, chn, n, len, off; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 242 | bool per_rank = false; |
| 243 | |
| 244 | BUG_ON(n_layers > EDAC_MAX_LAYERS || n_layers == 0); |
| 245 | /* |
| 246 | * Calculate the total amount of dimms and csrows/cschannels while |
| 247 | * in the old API emulation mode |
| 248 | */ |
| 249 | for (i = 0; i < n_layers; i++) { |
| 250 | tot_dimms *= layers[i].size; |
| 251 | if (layers[i].is_virt_csrow) |
| 252 | tot_csrows *= layers[i].size; |
| 253 | else |
| 254 | tot_channels *= layers[i].size; |
| 255 | |
| 256 | if (layers[i].type == EDAC_MC_LAYER_CHIP_SELECT) |
| 257 | per_rank = true; |
| 258 | } |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 259 | |
| 260 | /* Figure out the offsets of the various items from the start of an mc |
| 261 | * structure. We want the alignment of each item to be at least as |
| 262 | * stringent as what the compiler would provide if we could simply |
| 263 | * hardcode everything into a single struct. |
| 264 | */ |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 265 | mci = edac_align_ptr(&ptr, sizeof(*mci), 1); |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 266 | layer = edac_align_ptr(&ptr, sizeof(*layer), n_layers); |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 267 | for (i = 0; i < n_layers; i++) { |
| 268 | count *= layers[i].size; |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 269 | edac_dbg(4, "errcount layer %d size %d\n", i, count); |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 270 | ce_per_layer[i] = edac_align_ptr(&ptr, sizeof(u32), count); |
| 271 | ue_per_layer[i] = edac_align_ptr(&ptr, sizeof(u32), count); |
| 272 | tot_errcount += 2 * count; |
| 273 | } |
| 274 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 275 | edac_dbg(4, "allocating %d error counters\n", tot_errcount); |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 276 | pvt = edac_align_ptr(&ptr, sz_pvt, 1); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 277 | size = ((unsigned long)pvt) + sz_pvt; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 278 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 279 | edac_dbg(1, "allocating %u bytes for mci data (%d %s, %d csrows/channels)\n", |
| 280 | size, |
| 281 | tot_dimms, |
| 282 | per_rank ? "ranks" : "dimms", |
| 283 | tot_csrows * tot_channels); |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 284 | |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 285 | mci = kzalloc(size, GFP_KERNEL); |
| 286 | if (mci == NULL) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 287 | return NULL; |
| 288 | |
| 289 | /* Adjust pointers so they point within the memory we just allocated |
| 290 | * rather than an imaginary chunk of memory located at address 0. |
| 291 | */ |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 292 | layer = (struct edac_mc_layer *)(((char *)mci) + ((unsigned long)layer)); |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 293 | for (i = 0; i < n_layers; i++) { |
| 294 | mci->ce_per_layer[i] = (u32 *)((char *)mci + ((unsigned long)ce_per_layer[i])); |
| 295 | mci->ue_per_layer[i] = (u32 *)((char *)mci + ((unsigned long)ue_per_layer[i])); |
| 296 | } |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 297 | pvt = sz_pvt ? (((char *)mci) + ((unsigned long)pvt)) : NULL; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 298 | |
Doug Thompson | b8f6f97 | 2007-07-19 01:50:26 -0700 | [diff] [blame] | 299 | /* setup index and various internal pointers */ |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 300 | mci->mc_idx = mc_num; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 301 | mci->tot_dimms = tot_dimms; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 302 | mci->pvt_info = pvt; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 303 | mci->n_layers = n_layers; |
| 304 | mci->layers = layer; |
| 305 | memcpy(mci->layers, layers, sizeof(*layer) * n_layers); |
| 306 | mci->nr_csrows = tot_csrows; |
| 307 | mci->num_cschannel = tot_channels; |
| 308 | mci->mem_is_per_rank = per_rank; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 309 | |
Mauro Carvalho Chehab | a7d7d2e | 2012-01-27 14:12:32 -0300 | [diff] [blame] | 310 | /* |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 311 | * Alocate and fill the csrow/channels structs |
Mauro Carvalho Chehab | a7d7d2e | 2012-01-27 14:12:32 -0300 | [diff] [blame] | 312 | */ |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 313 | mci->csrows = kcalloc(sizeof(*mci->csrows), tot_csrows, GFP_KERNEL); |
| 314 | if (!mci->csrows) |
| 315 | goto error; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 316 | for (row = 0; row < tot_csrows; row++) { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 317 | csr = kzalloc(sizeof(**mci->csrows), GFP_KERNEL); |
| 318 | if (!csr) |
| 319 | goto error; |
| 320 | mci->csrows[row] = csr; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 321 | csr->csrow_idx = row; |
| 322 | csr->mci = mci; |
| 323 | csr->nr_channels = tot_channels; |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 324 | csr->channels = kcalloc(sizeof(*csr->channels), tot_channels, |
| 325 | GFP_KERNEL); |
| 326 | if (!csr->channels) |
| 327 | goto error; |
Mauro Carvalho Chehab | a7d7d2e | 2012-01-27 14:12:32 -0300 | [diff] [blame] | 328 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 329 | for (chn = 0; chn < tot_channels; chn++) { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 330 | chan = kzalloc(sizeof(**csr->channels), GFP_KERNEL); |
| 331 | if (!chan) |
| 332 | goto error; |
| 333 | csr->channels[chn] = chan; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 334 | chan->chan_idx = chn; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 335 | chan->csrow = csr; |
| 336 | } |
| 337 | } |
Mauro Carvalho Chehab | a7d7d2e | 2012-01-27 14:12:32 -0300 | [diff] [blame] | 338 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 339 | /* |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 340 | * Allocate and fill the dimm structs |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 341 | */ |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 342 | mci->dimms = kcalloc(sizeof(*mci->dimms), tot_dimms, GFP_KERNEL); |
| 343 | if (!mci->dimms) |
| 344 | goto error; |
| 345 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 346 | memset(&pos, 0, sizeof(pos)); |
| 347 | row = 0; |
| 348 | chn = 0; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 349 | for (i = 0; i < tot_dimms; i++) { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 350 | chan = mci->csrows[row]->channels[chn]; |
| 351 | off = EDAC_DIMM_OFF(layer, n_layers, pos[0], pos[1], pos[2]); |
| 352 | if (off < 0 || off >= tot_dimms) { |
| 353 | edac_mc_printk(mci, KERN_ERR, "EDAC core bug: EDAC_DIMM_OFF is trying to do an illegal data access\n"); |
| 354 | goto error; |
| 355 | } |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 356 | |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 357 | dimm = kzalloc(sizeof(**mci->dimms), GFP_KERNEL); |
Dan Carpenter | 08a4a13 | 2012-05-18 15:51:02 +0300 | [diff] [blame] | 358 | if (!dimm) |
| 359 | goto error; |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 360 | mci->dimms[off] = dimm; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 361 | dimm->mci = mci; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 362 | |
Mauro Carvalho Chehab | 5926ff5 | 2012-02-09 11:05:20 -0300 | [diff] [blame] | 363 | /* |
| 364 | * Copy DIMM location and initialize it. |
| 365 | */ |
| 366 | len = sizeof(dimm->label); |
| 367 | p = dimm->label; |
| 368 | n = snprintf(p, len, "mc#%u", mc_num); |
| 369 | p += n; |
| 370 | len -= n; |
| 371 | for (j = 0; j < n_layers; j++) { |
| 372 | n = snprintf(p, len, "%s#%u", |
| 373 | edac_layer_name[layers[j].type], |
| 374 | pos[j]); |
| 375 | p += n; |
| 376 | len -= n; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 377 | dimm->location[j] = pos[j]; |
| 378 | |
Mauro Carvalho Chehab | 5926ff5 | 2012-02-09 11:05:20 -0300 | [diff] [blame] | 379 | if (len <= 0) |
| 380 | break; |
| 381 | } |
| 382 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 383 | /* Link it to the csrows old API data */ |
| 384 | chan->dimm = dimm; |
| 385 | dimm->csrow = row; |
| 386 | dimm->cschannel = chn; |
| 387 | |
| 388 | /* Increment csrow location */ |
| 389 | row++; |
| 390 | if (row == tot_csrows) { |
| 391 | row = 0; |
| 392 | chn++; |
| 393 | } |
| 394 | |
| 395 | /* Increment dimm location */ |
| 396 | for (j = n_layers - 1; j >= 0; j--) { |
| 397 | pos[j]++; |
| 398 | if (pos[j] < layers[j].size) |
| 399 | break; |
| 400 | pos[j] = 0; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 404 | mci->op_state = OP_ALLOC; |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 405 | |
| 406 | /* at this point, the root kobj is valid, and in order to |
| 407 | * 'free' the object, then the function: |
| 408 | * edac_mc_unregister_sysfs_main_kobj() must be called |
| 409 | * which will perform kobj unregistration and the actual free |
| 410 | * will occur during the kobject callback operation |
| 411 | */ |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 412 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 413 | return mci; |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 414 | |
| 415 | error: |
| 416 | if (mci->dimms) { |
| 417 | for (i = 0; i < tot_dimms; i++) |
| 418 | kfree(mci->dimms[i]); |
| 419 | kfree(mci->dimms); |
| 420 | } |
| 421 | if (mci->csrows) { |
| 422 | for (chn = 0; chn < tot_channels; chn++) { |
| 423 | csr = mci->csrows[chn]; |
| 424 | if (csr) { |
| 425 | for (chn = 0; chn < tot_channels; chn++) |
| 426 | kfree(csr->channels[chn]); |
| 427 | kfree(csr); |
| 428 | } |
| 429 | kfree(mci->csrows[i]); |
| 430 | } |
| 431 | kfree(mci->csrows); |
| 432 | } |
| 433 | kfree(mci); |
| 434 | |
| 435 | return NULL; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 436 | } |
Dave Peterson | 9110540 | 2006-03-26 01:38:55 -0800 | [diff] [blame] | 437 | EXPORT_SYMBOL_GPL(edac_mc_alloc); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 438 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 439 | /** |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 440 | * edac_mc_free |
| 441 | * 'Free' a previously allocated 'mci' structure |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 442 | * @mci: pointer to a struct mem_ctl_info structure |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 443 | */ |
| 444 | void edac_mc_free(struct mem_ctl_info *mci) |
| 445 | { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 446 | edac_dbg(1, "\n"); |
Mauro Carvalho Chehab | bbc560a | 2010-08-16 18:22:43 -0300 | [diff] [blame] | 447 | |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 448 | /* the mci instance is freed here, when the sysfs object is dropped */ |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 449 | edac_unregister_sysfs(mci); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 450 | } |
Dave Peterson | 9110540 | 2006-03-26 01:38:55 -0800 | [diff] [blame] | 451 | EXPORT_SYMBOL_GPL(edac_mc_free); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 452 | |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 453 | |
Mauro Carvalho Chehab | 939747bd | 2010-08-10 11:22:01 -0300 | [diff] [blame] | 454 | /** |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 455 | * find_mci_by_dev |
| 456 | * |
| 457 | * scan list of controllers looking for the one that manages |
| 458 | * the 'dev' device |
Mauro Carvalho Chehab | 939747bd | 2010-08-10 11:22:01 -0300 | [diff] [blame] | 459 | * @dev: pointer to a struct device related with the MCI |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 460 | */ |
Mauro Carvalho Chehab | 939747bd | 2010-08-10 11:22:01 -0300 | [diff] [blame] | 461 | struct mem_ctl_info *find_mci_by_dev(struct device *dev) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 462 | { |
| 463 | struct mem_ctl_info *mci; |
| 464 | struct list_head *item; |
| 465 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 466 | edac_dbg(3, "\n"); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 467 | |
| 468 | list_for_each(item, &mc_devices) { |
| 469 | mci = list_entry(item, struct mem_ctl_info, link); |
| 470 | |
Mauro Carvalho Chehab | fd68750 | 2012-03-16 07:44:18 -0300 | [diff] [blame] | 471 | if (mci->pdev == dev) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 472 | return mci; |
| 473 | } |
| 474 | |
| 475 | return NULL; |
| 476 | } |
Mauro Carvalho Chehab | 939747bd | 2010-08-10 11:22:01 -0300 | [diff] [blame] | 477 | EXPORT_SYMBOL_GPL(find_mci_by_dev); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 478 | |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 479 | /* |
| 480 | * handler for EDAC to check if NMI type handler has asserted interrupt |
| 481 | */ |
| 482 | static int edac_mc_assert_error_check_and_clear(void) |
| 483 | { |
Dave Jiang | 66ee2f9 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 484 | int old_state; |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 485 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 486 | if (edac_op_state == EDAC_OPSTATE_POLL) |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 487 | return 1; |
| 488 | |
Dave Jiang | 66ee2f9 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 489 | old_state = edac_err_assert; |
| 490 | edac_err_assert = 0; |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 491 | |
Dave Jiang | 66ee2f9 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 492 | return old_state; |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | /* |
| 496 | * edac_mc_workq_function |
| 497 | * performs the operation scheduled by a workq request |
| 498 | */ |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 499 | static void edac_mc_workq_function(struct work_struct *work_req) |
| 500 | { |
Jean Delvare | fbeb438 | 2009-04-13 14:40:21 -0700 | [diff] [blame] | 501 | struct delayed_work *d_work = to_delayed_work(work_req); |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 502 | struct mem_ctl_info *mci = to_edac_mem_ctl_work(d_work); |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 503 | |
| 504 | mutex_lock(&mem_ctls_mutex); |
| 505 | |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 506 | /* if this control struct has movd to offline state, we are done */ |
| 507 | if (mci->op_state == OP_OFFLINE) { |
| 508 | mutex_unlock(&mem_ctls_mutex); |
| 509 | return; |
| 510 | } |
| 511 | |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 512 | /* Only poll controllers that are running polled and have a check */ |
| 513 | if (edac_mc_assert_error_check_and_clear() && (mci->edac_check != NULL)) |
| 514 | mci->edac_check(mci); |
| 515 | |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 516 | mutex_unlock(&mem_ctls_mutex); |
| 517 | |
| 518 | /* Reschedule */ |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 519 | queue_delayed_work(edac_workqueue, &mci->work, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 520 | msecs_to_jiffies(edac_mc_get_poll_msec())); |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | /* |
| 524 | * edac_mc_workq_setup |
| 525 | * initialize a workq item for this mci |
| 526 | * passing in the new delay period in msec |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 527 | * |
| 528 | * locking model: |
| 529 | * |
| 530 | * called with the mem_ctls_mutex held |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 531 | */ |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 532 | static void edac_mc_workq_setup(struct mem_ctl_info *mci, unsigned msec) |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 533 | { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 534 | edac_dbg(0, "\n"); |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 535 | |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 536 | /* if this instance is not in the POLL state, then simply return */ |
| 537 | if (mci->op_state != OP_RUNNING_POLL) |
| 538 | return; |
| 539 | |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 540 | INIT_DELAYED_WORK(&mci->work, edac_mc_workq_function); |
Tejun Heo | 41f63c5 | 2012-08-03 10:30:47 -0700 | [diff] [blame^] | 541 | mod_delayed_work(edac_workqueue, &mci->work, msecs_to_jiffies(msec)); |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | /* |
| 545 | * edac_mc_workq_teardown |
| 546 | * stop the workq processing on this mci |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 547 | * |
| 548 | * locking model: |
| 549 | * |
| 550 | * called WITHOUT lock held |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 551 | */ |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 552 | static void edac_mc_workq_teardown(struct mem_ctl_info *mci) |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 553 | { |
| 554 | int status; |
| 555 | |
Borislav Petkov | 00740c5 | 2010-09-26 12:42:23 +0200 | [diff] [blame] | 556 | if (mci->op_state != OP_RUNNING_POLL) |
| 557 | return; |
| 558 | |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 559 | status = cancel_delayed_work(&mci->work); |
| 560 | if (status == 0) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 561 | edac_dbg(0, "not canceled, flush the queue\n"); |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 562 | |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 563 | /* workq instance might be running, wait for it */ |
| 564 | flush_workqueue(edac_workqueue); |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | |
| 568 | /* |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 569 | * edac_mc_reset_delay_period(unsigned long value) |
| 570 | * |
| 571 | * user space has updated our poll period value, need to |
| 572 | * reset our workq delays |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 573 | */ |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 574 | void edac_mc_reset_delay_period(int value) |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 575 | { |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 576 | struct mem_ctl_info *mci; |
| 577 | struct list_head *item; |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 578 | |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 579 | mutex_lock(&mem_ctls_mutex); |
| 580 | |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 581 | list_for_each(item, &mc_devices) { |
| 582 | mci = list_entry(item, struct mem_ctl_info, link); |
| 583 | |
| 584 | edac_mc_workq_setup(mci, (unsigned long) value); |
| 585 | } |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 586 | |
| 587 | mutex_unlock(&mem_ctls_mutex); |
| 588 | } |
| 589 | |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 590 | |
| 591 | |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 592 | /* Return 0 on success, 1 on failure. |
| 593 | * Before calling this function, caller must |
| 594 | * assign a unique value to mci->mc_idx. |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 595 | * |
| 596 | * locking model: |
| 597 | * |
| 598 | * called with the mem_ctls_mutex lock held |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 599 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 600 | static int add_mc_to_global_list(struct mem_ctl_info *mci) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 601 | { |
| 602 | struct list_head *item, *insert_before; |
| 603 | struct mem_ctl_info *p; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 604 | |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 605 | insert_before = &mc_devices; |
| 606 | |
Mauro Carvalho Chehab | fd68750 | 2012-03-16 07:44:18 -0300 | [diff] [blame] | 607 | p = find_mci_by_dev(mci->pdev); |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 608 | if (unlikely(p != NULL)) |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 609 | goto fail0; |
| 610 | |
| 611 | list_for_each(item, &mc_devices) { |
| 612 | p = list_entry(item, struct mem_ctl_info, link); |
| 613 | |
| 614 | if (p->mc_idx >= mci->mc_idx) { |
| 615 | if (unlikely(p->mc_idx == mci->mc_idx)) |
| 616 | goto fail1; |
| 617 | |
| 618 | insert_before = item; |
| 619 | break; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 620 | } |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | list_add_tail_rcu(&mci->link, insert_before); |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 624 | atomic_inc(&edac_handlers); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 625 | return 0; |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 626 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 627 | fail0: |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 628 | edac_printk(KERN_WARNING, EDAC_MC, |
Mauro Carvalho Chehab | fd68750 | 2012-03-16 07:44:18 -0300 | [diff] [blame] | 629 | "%s (%s) %s %s already assigned %d\n", dev_name(p->pdev), |
Stephen Rothwell | 17aa7e0 | 2008-05-05 13:54:19 +1000 | [diff] [blame] | 630 | edac_dev_name(mci), p->mod_name, p->ctl_name, p->mc_idx); |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 631 | return 1; |
| 632 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 633 | fail1: |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 634 | edac_printk(KERN_WARNING, EDAC_MC, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 635 | "bug in low-level driver: attempt to assign\n" |
| 636 | " duplicate mc_idx %d in %s()\n", p->mc_idx, __func__); |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 637 | return 1; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 638 | } |
| 639 | |
Dave Peterson | e7ecd89 | 2006-03-26 01:38:52 -0800 | [diff] [blame] | 640 | static void del_mc_from_global_list(struct mem_ctl_info *mci) |
Dave Peterson | a1d03fc | 2006-03-26 01:38:46 -0800 | [diff] [blame] | 641 | { |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 642 | atomic_dec(&edac_handlers); |
Dave Peterson | a1d03fc | 2006-03-26 01:38:46 -0800 | [diff] [blame] | 643 | list_del_rcu(&mci->link); |
Lai Jiangshan | e2e7709 | 2011-05-26 16:25:58 -0700 | [diff] [blame] | 644 | |
| 645 | /* these are for safe removal of devices from global list while |
| 646 | * NMI handlers may be traversing list |
| 647 | */ |
| 648 | synchronize_rcu(); |
| 649 | INIT_LIST_HEAD(&mci->link); |
Dave Peterson | a1d03fc | 2006-03-26 01:38:46 -0800 | [diff] [blame] | 650 | } |
| 651 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 652 | /** |
Douglas Thompson | 5da0831 | 2007-07-19 01:49:31 -0700 | [diff] [blame] | 653 | * edac_mc_find: Search for a mem_ctl_info structure whose index is 'idx'. |
| 654 | * |
| 655 | * If found, return a pointer to the structure. |
| 656 | * Else return NULL. |
| 657 | * |
| 658 | * Caller must hold mem_ctls_mutex. |
| 659 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 660 | struct mem_ctl_info *edac_mc_find(int idx) |
Douglas Thompson | 5da0831 | 2007-07-19 01:49:31 -0700 | [diff] [blame] | 661 | { |
| 662 | struct list_head *item; |
| 663 | struct mem_ctl_info *mci; |
| 664 | |
| 665 | list_for_each(item, &mc_devices) { |
| 666 | mci = list_entry(item, struct mem_ctl_info, link); |
| 667 | |
| 668 | if (mci->mc_idx >= idx) { |
| 669 | if (mci->mc_idx == idx) |
| 670 | return mci; |
| 671 | |
| 672 | break; |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | return NULL; |
| 677 | } |
| 678 | EXPORT_SYMBOL(edac_mc_find); |
| 679 | |
| 680 | /** |
Dave Peterson | 472678e | 2006-03-26 01:38:49 -0800 | [diff] [blame] | 681 | * edac_mc_add_mc: Insert the 'mci' structure into the mci global list and |
| 682 | * create sysfs entries associated with mci structure |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 683 | * @mci: pointer to the mci structure to be added to the list |
| 684 | * |
| 685 | * Return: |
| 686 | * 0 Success |
| 687 | * !0 Failure |
| 688 | */ |
| 689 | |
| 690 | /* FIXME - should a warning be printed if no error detection? correction? */ |
Doug Thompson | b8f6f97 | 2007-07-19 01:50:26 -0700 | [diff] [blame] | 691 | int edac_mc_add_mc(struct mem_ctl_info *mci) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 692 | { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 693 | edac_dbg(0, "\n"); |
Doug Thompson | b8f6f97 | 2007-07-19 01:50:26 -0700 | [diff] [blame] | 694 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 695 | #ifdef CONFIG_EDAC_DEBUG |
| 696 | if (edac_debug_level >= 3) |
| 697 | edac_mc_dump_mci(mci); |
Dave Peterson | e7ecd89 | 2006-03-26 01:38:52 -0800 | [diff] [blame] | 698 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 699 | if (edac_debug_level >= 4) { |
| 700 | int i; |
| 701 | |
| 702 | for (i = 0; i < mci->nr_csrows; i++) { |
Mauro Carvalho Chehab | 6e84d35 | 2012-04-30 10:24:43 -0300 | [diff] [blame] | 703 | struct csrow_info *csrow = mci->csrows[i]; |
| 704 | u32 nr_pages = 0; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 705 | int j; |
Dave Peterson | e7ecd89 | 2006-03-26 01:38:52 -0800 | [diff] [blame] | 706 | |
Mauro Carvalho Chehab | 6e84d35 | 2012-04-30 10:24:43 -0300 | [diff] [blame] | 707 | for (j = 0; j < csrow->nr_channels; j++) |
| 708 | nr_pages += csrow->channels[j]->dimm->nr_pages; |
| 709 | if (!nr_pages) |
| 710 | continue; |
| 711 | edac_mc_dump_csrow(csrow); |
| 712 | for (j = 0; j < csrow->nr_channels; j++) |
| 713 | if (csrow->channels[j]->dimm->nr_pages) |
| 714 | edac_mc_dump_channel(csrow->channels[j]); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 715 | } |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 716 | for (i = 0; i < mci->tot_dimms; i++) |
Mauro Carvalho Chehab | 6e84d35 | 2012-04-30 10:24:43 -0300 | [diff] [blame] | 717 | if (mci->dimms[i]->nr_pages) |
| 718 | edac_mc_dump_dimm(mci->dimms[i], i); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 719 | } |
| 720 | #endif |
Matthias Kaehlcke | 63b7df9 | 2007-07-19 01:49:38 -0700 | [diff] [blame] | 721 | mutex_lock(&mem_ctls_mutex); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 722 | |
| 723 | if (add_mc_to_global_list(mci)) |
Dave Peterson | 028a7b6 | 2006-03-26 01:38:47 -0800 | [diff] [blame] | 724 | goto fail0; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 725 | |
| 726 | /* set load time so that error rate can be tracked */ |
| 727 | mci->start_time = jiffies; |
| 728 | |
eric wollesen | 9794f33 | 2007-02-12 00:53:08 -0800 | [diff] [blame] | 729 | if (edac_create_sysfs_mci_device(mci)) { |
| 730 | edac_mc_printk(mci, KERN_WARNING, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 731 | "failed to create sysfs device\n"); |
eric wollesen | 9794f33 | 2007-02-12 00:53:08 -0800 | [diff] [blame] | 732 | goto fail1; |
| 733 | } |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 734 | |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 735 | /* If there IS a check routine, then we are running POLLED */ |
| 736 | if (mci->edac_check != NULL) { |
| 737 | /* This instance is NOW RUNNING */ |
| 738 | mci->op_state = OP_RUNNING_POLL; |
| 739 | |
| 740 | edac_mc_workq_setup(mci, edac_mc_get_poll_msec()); |
| 741 | } else { |
| 742 | mci->op_state = OP_RUNNING_INTERRUPT; |
| 743 | } |
| 744 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 745 | /* Report action taken */ |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 746 | edac_mc_printk(mci, KERN_INFO, "Giving out device to '%s' '%s':" |
Stephen Rothwell | 17aa7e0 | 2008-05-05 13:54:19 +1000 | [diff] [blame] | 747 | " DEV %s\n", mci->mod_name, mci->ctl_name, edac_dev_name(mci)); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 748 | |
Matthias Kaehlcke | 63b7df9 | 2007-07-19 01:49:38 -0700 | [diff] [blame] | 749 | mutex_unlock(&mem_ctls_mutex); |
Dave Peterson | 028a7b6 | 2006-03-26 01:38:47 -0800 | [diff] [blame] | 750 | return 0; |
| 751 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 752 | fail1: |
Dave Peterson | 028a7b6 | 2006-03-26 01:38:47 -0800 | [diff] [blame] | 753 | del_mc_from_global_list(mci); |
| 754 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 755 | fail0: |
Matthias Kaehlcke | 63b7df9 | 2007-07-19 01:49:38 -0700 | [diff] [blame] | 756 | mutex_unlock(&mem_ctls_mutex); |
Dave Peterson | 028a7b6 | 2006-03-26 01:38:47 -0800 | [diff] [blame] | 757 | return 1; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 758 | } |
Dave Peterson | 9110540 | 2006-03-26 01:38:55 -0800 | [diff] [blame] | 759 | EXPORT_SYMBOL_GPL(edac_mc_add_mc); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 760 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 761 | /** |
Dave Peterson | 472678e | 2006-03-26 01:38:49 -0800 | [diff] [blame] | 762 | * edac_mc_del_mc: Remove sysfs entries for specified mci structure and |
| 763 | * remove mci structure from global list |
Doug Thompson | 37f0458 | 2006-06-30 01:56:07 -0700 | [diff] [blame] | 764 | * @pdev: Pointer to 'struct device' representing mci structure to remove. |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 765 | * |
Dave Peterson | 18dbc33 | 2006-03-26 01:38:50 -0800 | [diff] [blame] | 766 | * Return pointer to removed mci structure, or NULL if device not found. |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 767 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 768 | struct mem_ctl_info *edac_mc_del_mc(struct device *dev) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 769 | { |
Dave Peterson | 18dbc33 | 2006-03-26 01:38:50 -0800 | [diff] [blame] | 770 | struct mem_ctl_info *mci; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 771 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 772 | edac_dbg(0, "\n"); |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 773 | |
Matthias Kaehlcke | 63b7df9 | 2007-07-19 01:49:38 -0700 | [diff] [blame] | 774 | mutex_lock(&mem_ctls_mutex); |
Dave Peterson | 18dbc33 | 2006-03-26 01:38:50 -0800 | [diff] [blame] | 775 | |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 776 | /* find the requested mci struct in the global list */ |
| 777 | mci = find_mci_by_dev(dev); |
| 778 | if (mci == NULL) { |
Matthias Kaehlcke | 63b7df9 | 2007-07-19 01:49:38 -0700 | [diff] [blame] | 779 | mutex_unlock(&mem_ctls_mutex); |
Dave Peterson | 18dbc33 | 2006-03-26 01:38:50 -0800 | [diff] [blame] | 780 | return NULL; |
| 781 | } |
| 782 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 783 | del_mc_from_global_list(mci); |
Matthias Kaehlcke | 63b7df9 | 2007-07-19 01:49:38 -0700 | [diff] [blame] | 784 | mutex_unlock(&mem_ctls_mutex); |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 785 | |
Borislav Petkov | bb31b312 | 2010-12-02 17:48:35 +0100 | [diff] [blame] | 786 | /* flush workq processes */ |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 787 | edac_mc_workq_teardown(mci); |
Borislav Petkov | bb31b312 | 2010-12-02 17:48:35 +0100 | [diff] [blame] | 788 | |
| 789 | /* marking MCI offline */ |
| 790 | mci->op_state = OP_OFFLINE; |
| 791 | |
| 792 | /* remove from sysfs */ |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 793 | edac_remove_sysfs_mci_device(mci); |
| 794 | |
Dave Peterson | 537fba2 | 2006-03-26 01:38:40 -0800 | [diff] [blame] | 795 | edac_printk(KERN_INFO, EDAC_MC, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 796 | "Removed device %d for %s %s: DEV %s\n", mci->mc_idx, |
Stephen Rothwell | 17aa7e0 | 2008-05-05 13:54:19 +1000 | [diff] [blame] | 797 | mci->mod_name, mci->ctl_name, edac_dev_name(mci)); |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 798 | |
Dave Peterson | 18dbc33 | 2006-03-26 01:38:50 -0800 | [diff] [blame] | 799 | return mci; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 800 | } |
Dave Peterson | 9110540 | 2006-03-26 01:38:55 -0800 | [diff] [blame] | 801 | EXPORT_SYMBOL_GPL(edac_mc_del_mc); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 802 | |
Adrian Bunk | 2da1c11 | 2007-07-19 01:49:32 -0700 | [diff] [blame] | 803 | static void edac_mc_scrub_block(unsigned long page, unsigned long offset, |
| 804 | u32 size) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 805 | { |
| 806 | struct page *pg; |
| 807 | void *virt_addr; |
| 808 | unsigned long flags = 0; |
| 809 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 810 | edac_dbg(3, "\n"); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 811 | |
| 812 | /* ECC error page was not in our memory. Ignore it. */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 813 | if (!pfn_valid(page)) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 814 | return; |
| 815 | |
| 816 | /* Find the actual page structure then map it and fix */ |
| 817 | pg = pfn_to_page(page); |
| 818 | |
| 819 | if (PageHighMem(pg)) |
| 820 | local_irq_save(flags); |
| 821 | |
Cong Wang | 4e5df7c | 2011-11-25 23:14:19 +0800 | [diff] [blame] | 822 | virt_addr = kmap_atomic(pg); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 823 | |
| 824 | /* Perform architecture specific atomic scrub operation */ |
| 825 | atomic_scrub(virt_addr + offset, size); |
| 826 | |
| 827 | /* Unmap and complete */ |
Cong Wang | 4e5df7c | 2011-11-25 23:14:19 +0800 | [diff] [blame] | 828 | kunmap_atomic(virt_addr); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 829 | |
| 830 | if (PageHighMem(pg)) |
| 831 | local_irq_restore(flags); |
| 832 | } |
| 833 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 834 | /* FIXME - should return -1 */ |
Dave Peterson | e7ecd89 | 2006-03-26 01:38:52 -0800 | [diff] [blame] | 835 | 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] | 836 | { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 837 | struct csrow_info **csrows = mci->csrows; |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 838 | int row, i, j, n; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 839 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 840 | edac_dbg(1, "MC%d: 0x%lx\n", mci->mc_idx, page); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 841 | row = -1; |
| 842 | |
| 843 | for (i = 0; i < mci->nr_csrows; i++) { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 844 | struct csrow_info *csrow = csrows[i]; |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 845 | n = 0; |
| 846 | for (j = 0; j < csrow->nr_channels; j++) { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 847 | struct dimm_info *dimm = csrow->channels[j]->dimm; |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 848 | n += dimm->nr_pages; |
| 849 | } |
| 850 | if (n == 0) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 851 | continue; |
| 852 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 853 | edac_dbg(3, "MC%d: first(0x%lx) page(0x%lx) last(0x%lx) mask(0x%lx)\n", |
| 854 | mci->mc_idx, |
| 855 | csrow->first_page, page, csrow->last_page, |
| 856 | csrow->page_mask); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 857 | |
| 858 | if ((page >= csrow->first_page) && |
| 859 | (page <= csrow->last_page) && |
| 860 | ((page & csrow->page_mask) == |
| 861 | (csrow->first_page & csrow->page_mask))) { |
| 862 | row = i; |
| 863 | break; |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | if (row == -1) |
Dave Peterson | 537fba2 | 2006-03-26 01:38:40 -0800 | [diff] [blame] | 868 | edac_mc_printk(mci, KERN_ERR, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 869 | "could not look up page error address %lx\n", |
| 870 | (unsigned long)page); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 871 | |
| 872 | return row; |
| 873 | } |
Dave Peterson | 9110540 | 2006-03-26 01:38:55 -0800 | [diff] [blame] | 874 | EXPORT_SYMBOL_GPL(edac_mc_find_csrow_by_page); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 875 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 876 | const char *edac_layer_name[] = { |
| 877 | [EDAC_MC_LAYER_BRANCH] = "branch", |
| 878 | [EDAC_MC_LAYER_CHANNEL] = "channel", |
| 879 | [EDAC_MC_LAYER_SLOT] = "slot", |
| 880 | [EDAC_MC_LAYER_CHIP_SELECT] = "csrow", |
| 881 | }; |
| 882 | EXPORT_SYMBOL_GPL(edac_layer_name); |
| 883 | |
| 884 | static void edac_inc_ce_error(struct mem_ctl_info *mci, |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 885 | bool enable_per_layer_report, |
| 886 | const int pos[EDAC_MAX_LAYERS], |
| 887 | const u16 count) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 888 | { |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 889 | int i, index = 0; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 890 | |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 891 | mci->ce_mc += count; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 892 | |
| 893 | if (!enable_per_layer_report) { |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 894 | mci->ce_noinfo_count += count; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 895 | return; |
| 896 | } |
| 897 | |
| 898 | for (i = 0; i < mci->n_layers; i++) { |
| 899 | if (pos[i] < 0) |
| 900 | break; |
| 901 | index += pos[i]; |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 902 | mci->ce_per_layer[i][index] += count; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 903 | |
| 904 | if (i < mci->n_layers - 1) |
| 905 | index *= mci->layers[i + 1].size; |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | static void edac_inc_ue_error(struct mem_ctl_info *mci, |
| 910 | bool enable_per_layer_report, |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 911 | const int pos[EDAC_MAX_LAYERS], |
| 912 | const u16 count) |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 913 | { |
| 914 | int i, index = 0; |
| 915 | |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 916 | mci->ue_mc += count; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 917 | |
| 918 | if (!enable_per_layer_report) { |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 919 | mci->ce_noinfo_count += count; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 920 | return; |
| 921 | } |
| 922 | |
| 923 | for (i = 0; i < mci->n_layers; i++) { |
| 924 | if (pos[i] < 0) |
| 925 | break; |
| 926 | index += pos[i]; |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 927 | mci->ue_per_layer[i][index] += count; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 928 | |
| 929 | if (i < mci->n_layers - 1) |
| 930 | index *= mci->layers[i + 1].size; |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | static void edac_ce_error(struct mem_ctl_info *mci, |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 935 | const u16 error_count, |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 936 | const int pos[EDAC_MAX_LAYERS], |
| 937 | const char *msg, |
| 938 | const char *location, |
| 939 | const char *label, |
| 940 | const char *detail, |
| 941 | const char *other_detail, |
| 942 | const bool enable_per_layer_report, |
| 943 | const unsigned long page_frame_number, |
| 944 | const unsigned long offset_in_page, |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 945 | long grain) |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 946 | { |
| 947 | unsigned long remapped_page; |
| 948 | |
| 949 | if (edac_mc_get_log_ce()) { |
| 950 | if (other_detail && *other_detail) |
| 951 | edac_mc_printk(mci, KERN_WARNING, |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 952 | "%d CE %s on %s (%s %s - %s)\n", |
| 953 | error_count, |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 954 | msg, label, location, |
| 955 | detail, other_detail); |
| 956 | else |
| 957 | edac_mc_printk(mci, KERN_WARNING, |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 958 | "%d CE %s on %s (%s %s)\n", |
| 959 | error_count, |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 960 | msg, label, location, |
| 961 | detail); |
| 962 | } |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 963 | edac_inc_ce_error(mci, enable_per_layer_report, pos, error_count); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 964 | |
| 965 | if (mci->scrub_mode & SCRUB_SW_SRC) { |
| 966 | /* |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 967 | * Some memory controllers (called MCs below) can remap |
| 968 | * memory so that it is still available at a different |
| 969 | * address when PCI devices map into memory. |
| 970 | * MC's that can't do this, lose the memory where PCI |
| 971 | * devices are mapped. This mapping is MC-dependent |
| 972 | * and so we call back into the MC driver for it to |
| 973 | * map the MC page to a physical (CPU) page which can |
| 974 | * then be mapped to a virtual page - which can then |
| 975 | * be scrubbed. |
| 976 | */ |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 977 | remapped_page = mci->ctl_page_to_phys ? |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 978 | mci->ctl_page_to_phys(mci, page_frame_number) : |
| 979 | page_frame_number; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 980 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 981 | edac_mc_scrub_block(remapped_page, |
| 982 | offset_in_page, grain); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 986 | static void edac_ue_error(struct mem_ctl_info *mci, |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 987 | const u16 error_count, |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 988 | const int pos[EDAC_MAX_LAYERS], |
| 989 | const char *msg, |
| 990 | const char *location, |
| 991 | const char *label, |
| 992 | const char *detail, |
| 993 | const char *other_detail, |
| 994 | const bool enable_per_layer_report) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 995 | { |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 996 | if (edac_mc_get_log_ue()) { |
| 997 | if (other_detail && *other_detail) |
| 998 | edac_mc_printk(mci, KERN_WARNING, |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 999 | "%d UE %s on %s (%s %s - %s)\n", |
| 1000 | error_count, |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1001 | msg, label, location, detail, |
| 1002 | other_detail); |
| 1003 | else |
| 1004 | edac_mc_printk(mci, KERN_WARNING, |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 1005 | "%d UE %s on %s (%s %s)\n", |
| 1006 | error_count, |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1007 | msg, label, location, detail); |
| 1008 | } |
Dave Peterson | e7ecd89 | 2006-03-26 01:38:52 -0800 | [diff] [blame] | 1009 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1010 | if (edac_mc_get_panic_on_ue()) { |
| 1011 | if (other_detail && *other_detail) |
| 1012 | panic("UE %s on %s (%s%s - %s)\n", |
| 1013 | msg, label, location, detail, other_detail); |
| 1014 | else |
| 1015 | panic("UE %s on %s (%s%s)\n", |
| 1016 | msg, label, location, detail); |
| 1017 | } |
| 1018 | |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 1019 | edac_inc_ue_error(mci, enable_per_layer_report, pos, error_count); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1020 | } |
| 1021 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1022 | #define OTHER_LABEL " or " |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1023 | |
| 1024 | /** |
| 1025 | * edac_mc_handle_error - reports a memory event to userspace |
| 1026 | * |
| 1027 | * @type: severity of the error (CE/UE/Fatal) |
| 1028 | * @mci: a struct mem_ctl_info pointer |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 1029 | * @error_count: Number of errors of the same type |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1030 | * @page_frame_number: mem page where the error occurred |
| 1031 | * @offset_in_page: offset of the error inside the page |
| 1032 | * @syndrome: ECC syndrome |
| 1033 | * @top_layer: Memory layer[0] position |
| 1034 | * @mid_layer: Memory layer[1] position |
| 1035 | * @low_layer: Memory layer[2] position |
| 1036 | * @msg: Message meaningful to the end users that |
| 1037 | * explains the event |
| 1038 | * @other_detail: Technical details about the event that |
| 1039 | * may help hardware manufacturers and |
| 1040 | * EDAC developers to analyse the event |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1041 | */ |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1042 | void edac_mc_handle_error(const enum hw_event_mc_err_type type, |
| 1043 | struct mem_ctl_info *mci, |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 1044 | const u16 error_count, |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1045 | const unsigned long page_frame_number, |
| 1046 | const unsigned long offset_in_page, |
| 1047 | const unsigned long syndrome, |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1048 | const int top_layer, |
| 1049 | const int mid_layer, |
| 1050 | const int low_layer, |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1051 | const char *msg, |
Mauro Carvalho Chehab | 03f7eae | 2012-06-04 11:29:25 -0300 | [diff] [blame] | 1052 | const char *other_detail) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1053 | { |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1054 | /* FIXME: too much for stack: move it to some pre-alocated area */ |
| 1055 | char detail[80], location[80]; |
| 1056 | char label[(EDAC_MC_LABEL_LEN + 1 + sizeof(OTHER_LABEL)) * mci->tot_dimms]; |
| 1057 | char *p; |
| 1058 | int row = -1, chan = -1; |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1059 | int pos[EDAC_MAX_LAYERS] = { top_layer, mid_layer, low_layer }; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1060 | int i; |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1061 | long grain; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1062 | bool enable_per_layer_report = false; |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1063 | u8 grain_bits; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1064 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1065 | edac_dbg(3, "MC%d\n", mci->mc_idx); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1066 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1067 | /* |
| 1068 | * Check if the event report is consistent and if the memory |
| 1069 | * location is known. If it is known, enable_per_layer_report will be |
| 1070 | * true, the DIMM(s) label info will be filled and the per-layer |
| 1071 | * error counters will be incremented. |
| 1072 | */ |
| 1073 | for (i = 0; i < mci->n_layers; i++) { |
| 1074 | if (pos[i] >= (int)mci->layers[i].size) { |
| 1075 | if (type == HW_EVENT_ERR_CORRECTED) |
| 1076 | p = "CE"; |
| 1077 | else |
| 1078 | p = "UE"; |
| 1079 | |
| 1080 | edac_mc_printk(mci, KERN_ERR, |
| 1081 | "INTERNAL ERROR: %s value is out of range (%d >= %d)\n", |
| 1082 | edac_layer_name[mci->layers[i].type], |
| 1083 | pos[i], mci->layers[i].size); |
| 1084 | /* |
| 1085 | * Instead of just returning it, let's use what's |
| 1086 | * known about the error. The increment routines and |
| 1087 | * the DIMM filter logic will do the right thing by |
| 1088 | * pointing the likely damaged DIMMs. |
| 1089 | */ |
| 1090 | pos[i] = -1; |
| 1091 | } |
| 1092 | if (pos[i] >= 0) |
| 1093 | enable_per_layer_report = true; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1094 | } |
| 1095 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1096 | /* |
| 1097 | * Get the dimm label/grain that applies to the match criteria. |
| 1098 | * As the error algorithm may not be able to point to just one memory |
| 1099 | * stick, the logic here will get all possible labels that could |
| 1100 | * pottentially be affected by the error. |
| 1101 | * On FB-DIMM memory controllers, for uncorrected errors, it is common |
| 1102 | * to have only the MC channel and the MC dimm (also called "branch") |
| 1103 | * but the channel is not known, as the memory is arranged in pairs, |
| 1104 | * where each memory belongs to a separate channel within the same |
| 1105 | * branch. |
| 1106 | */ |
| 1107 | grain = 0; |
| 1108 | p = label; |
| 1109 | *p = '\0'; |
| 1110 | for (i = 0; i < mci->tot_dimms; i++) { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 1111 | struct dimm_info *dimm = mci->dimms[i]; |
Dave Peterson | e7ecd89 | 2006-03-26 01:38:52 -0800 | [diff] [blame] | 1112 | |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1113 | if (top_layer >= 0 && top_layer != dimm->location[0]) |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1114 | continue; |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1115 | if (mid_layer >= 0 && mid_layer != dimm->location[1]) |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1116 | continue; |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1117 | if (low_layer >= 0 && low_layer != dimm->location[2]) |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1118 | continue; |
| 1119 | |
| 1120 | /* get the max grain, over the error match range */ |
| 1121 | if (dimm->grain > grain) |
| 1122 | grain = dimm->grain; |
| 1123 | |
| 1124 | /* |
| 1125 | * If the error is memory-controller wide, there's no need to |
| 1126 | * seek for the affected DIMMs because the whole |
| 1127 | * channel/memory controller/... may be affected. |
| 1128 | * Also, don't show errors for empty DIMM slots. |
| 1129 | */ |
| 1130 | if (enable_per_layer_report && dimm->nr_pages) { |
| 1131 | if (p != label) { |
| 1132 | strcpy(p, OTHER_LABEL); |
| 1133 | p += strlen(OTHER_LABEL); |
| 1134 | } |
| 1135 | strcpy(p, dimm->label); |
| 1136 | p += strlen(p); |
| 1137 | *p = '\0'; |
| 1138 | |
| 1139 | /* |
| 1140 | * get csrow/channel of the DIMM, in order to allow |
| 1141 | * incrementing the compat API counters |
| 1142 | */ |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1143 | edac_dbg(4, "%s csrows map: (%d,%d)\n", |
| 1144 | mci->mem_is_per_rank ? "rank" : "dimm", |
| 1145 | dimm->csrow, dimm->cschannel); |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1146 | if (row == -1) |
| 1147 | row = dimm->csrow; |
| 1148 | else if (row >= 0 && row != dimm->csrow) |
| 1149 | row = -2; |
| 1150 | |
| 1151 | if (chan == -1) |
| 1152 | chan = dimm->cschannel; |
| 1153 | else if (chan >= 0 && chan != dimm->cschannel) |
| 1154 | chan = -2; |
| 1155 | } |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1156 | } |
| 1157 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1158 | if (!enable_per_layer_report) { |
| 1159 | strcpy(label, "any memory"); |
| 1160 | } else { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1161 | edac_dbg(4, "csrow/channel to increment: (%d,%d)\n", row, chan); |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1162 | if (p == label) |
| 1163 | strcpy(label, "unknown memory"); |
| 1164 | if (type == HW_EVENT_ERR_CORRECTED) { |
| 1165 | if (row >= 0) { |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 1166 | mci->csrows[row]->ce_count += error_count; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1167 | if (chan >= 0) |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 1168 | mci->csrows[row]->channels[chan]->ce_count += error_count; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1169 | } |
| 1170 | } else |
| 1171 | if (row >= 0) |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 1172 | mci->csrows[row]->ue_count += error_count; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1173 | } |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1174 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1175 | /* Fill the RAM location data */ |
| 1176 | p = location; |
| 1177 | for (i = 0; i < mci->n_layers; i++) { |
| 1178 | if (pos[i] < 0) |
| 1179 | continue; |
| 1180 | |
| 1181 | p += sprintf(p, "%s:%d ", |
| 1182 | edac_layer_name[mci->layers[i].type], |
| 1183 | pos[i]); |
| 1184 | } |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1185 | if (p > location) |
| 1186 | *(p - 1) = '\0'; |
| 1187 | |
| 1188 | /* Report the error via the trace interface */ |
| 1189 | |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1190 | grain_bits = fls_long(grain) + 1; |
| 1191 | trace_mc_event(type, msg, label, error_count, |
| 1192 | mci->mc_idx, top_layer, mid_layer, low_layer, |
| 1193 | PAGES_TO_MiB(page_frame_number) | offset_in_page, |
| 1194 | grain_bits, syndrome, other_detail); |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1195 | |
| 1196 | /* Memory type dependent details about the error */ |
| 1197 | if (type == HW_EVENT_ERR_CORRECTED) { |
| 1198 | snprintf(detail, sizeof(detail), |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1199 | "page:0x%lx offset:0x%lx grain:%ld syndrome:0x%lx", |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 1200 | page_frame_number, offset_in_page, |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1201 | grain, syndrome); |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 1202 | edac_ce_error(mci, error_count, pos, msg, location, label, |
| 1203 | detail, other_detail, enable_per_layer_report, |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1204 | page_frame_number, offset_in_page, grain); |
| 1205 | } else { |
| 1206 | snprintf(detail, sizeof(detail), |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1207 | "page:0x%lx offset:0x%lx grain:%ld", |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1208 | page_frame_number, offset_in_page, grain); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1209 | |
Mauro Carvalho Chehab | 9eb07a7 | 2012-06-04 13:27:43 -0300 | [diff] [blame] | 1210 | edac_ue_error(mci, error_count, pos, msg, location, label, |
| 1211 | detail, other_detail, enable_per_layer_report); |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1212 | } |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1213 | } |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1214 | EXPORT_SYMBOL_GPL(edac_mc_handle_error); |