blob: d1e9eb191f2bd77ff72614c0819885d31dcf473d [file] [log] [blame]
Alan Coxda9bb1d2006-01-18 17:44:13 -08001/*
2 * edac_mc kernel module
Doug Thompson49c0dab72006-07-10 04:45:19 -07003 * (C) 2005, 2006 Linux Networx (http://lnxi.com)
Alan Coxda9bb1d2006-01-18 17:44:13 -08004 * This file may be distributed under the terms of the
5 * GNU General Public License.
6 *
7 * Written by Thayne Harbaugh
8 * Based on work by Dan Hollis <goemon at anime dot net> and others.
9 * http://www.anime.net/~goemon/linux-ecc/
10 *
11 * Modified by Dave Peterson and Doug Thompson
12 *
13 */
14
Alan Coxda9bb1d2006-01-18 17:44:13 -080015#include <linux/module.h>
16#include <linux/proc_fs.h>
17#include <linux/kernel.h>
18#include <linux/types.h>
19#include <linux/smp.h>
20#include <linux/init.h>
21#include <linux/sysctl.h>
22#include <linux/highmem.h>
23#include <linux/timer.h>
24#include <linux/slab.h>
25#include <linux/jiffies.h>
26#include <linux/spinlock.h>
27#include <linux/list.h>
Alan Coxda9bb1d2006-01-18 17:44:13 -080028#include <linux/ctype.h>
Dave Jiangc0d12172007-07-19 01:49:46 -070029#include <linux/edac.h>
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -030030#include <linux/bitops.h>
Alan Coxda9bb1d2006-01-18 17:44:13 -080031#include <asm/uaccess.h>
32#include <asm/page.h>
33#include <asm/edac.h>
Douglas Thompson20bcb7a2007-07-19 01:49:47 -070034#include "edac_core.h"
Douglas Thompson7c9281d2007-07-19 01:49:33 -070035#include "edac_module.h"
Alan Coxda9bb1d2006-01-18 17:44:13 -080036
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -030037#define CREATE_TRACE_POINTS
38#define TRACE_INCLUDE_PATH ../../include/ras
39#include <ras/ras_event.h>
40
Alan Coxda9bb1d2006-01-18 17:44:13 -080041/* lock to memory controller's control array */
Matthias Kaehlcke63b7df92007-07-19 01:49:38 -070042static DEFINE_MUTEX(mem_ctls_mutex);
Robert P. J. Dayff6ac2a2008-04-29 01:03:17 -070043static LIST_HEAD(mc_devices);
Alan Coxda9bb1d2006-01-18 17:44:13 -080044
Mauro Carvalho Chehab6e84d352012-04-30 10:24:43 -030045unsigned 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 Coxda9bb1d2006-01-18 17:44:13 -080066#ifdef CONFIG_EDAC_DEBUG
67
Mauro Carvalho Chehaba4b4be32012-01-27 10:26:13 -030068static void edac_mc_dump_channel(struct rank_info *chan)
Alan Coxda9bb1d2006-01-18 17:44:13 -080069{
Mauro Carvalho Chehab6e84d352012-04-30 10:24:43 -030070 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 Chehab4275be62012-04-18 15:20:50 -030074}
75
Mauro Carvalho Chehab6e84d352012-04-30 10:24:43 -030076static void edac_mc_dump_dimm(struct dimm_info *dimm, int number)
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -030077{
Mauro Carvalho Chehab6e84d352012-04-30 10:24:43 -030078 char location[80];
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -030079
Mauro Carvalho Chehab6e84d352012-04-30 10:24:43 -030080 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 Coxda9bb1d2006-01-18 17:44:13 -080090}
91
Adrian Bunk2da1c112007-07-19 01:49:32 -070092static void edac_mc_dump_csrow(struct csrow_info *csrow)
Alan Coxda9bb1d2006-01-18 17:44:13 -080093{
Mauro Carvalho Chehab6e84d352012-04-30 10:24:43 -030094 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 Coxda9bb1d2006-01-18 17:44:13 -0800102}
103
Adrian Bunk2da1c112007-07-19 01:49:32 -0700104static void edac_mc_dump_mci(struct mem_ctl_info *mci)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800105{
Joe Perches956b9ba2012-04-29 17:08:39 -0300106 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 Coxda9bb1d2006-01-18 17:44:13 -0800119}
120
Borislav Petkov24f9a7f2010-10-07 18:29:15 +0200121#endif /* CONFIG_EDAC_DEBUG */
122
Borislav Petkov239642f2009-11-12 15:33:16 +0100123/*
124 * keep those in sync with the enum mem_type
125 */
126const 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};
145EXPORT_SYMBOL_GPL(edac_mem_types);
146
Mauro Carvalho Chehab93e4fe62012-04-16 10:18:12 -0300147/**
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 Coxda9bb1d2006-01-18 17:44:13 -0800153 *
154 * If 'size' is a constant, the compiler will optimize this whole function
Mauro Carvalho Chehab93e4fe62012-04-16 10:18:12 -0300155 * 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 Coxda9bb1d2006-01-18 17:44:13 -0800164 */
Mauro Carvalho Chehab93e4fe62012-04-16 10:18:12 -0300165void *edac_align_ptr(void **p, unsigned size, int n_elems)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800166{
167 unsigned align, r;
Mauro Carvalho Chehab93e4fe62012-04-16 10:18:12 -0300168 void *ptr = *p;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800169
Mauro Carvalho Chehab93e4fe62012-04-16 10:18:12 -0300170 *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 Coxda9bb1d2006-01-18 17:44:13 -0800178 * 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 Thompson079708b2007-07-19 01:49:58 -0700190 return (char *)ptr;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800191
Chris Metcalf8447c4d12012-06-06 13:11:05 -0400192 r = (unsigned long)p % align;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800193
194 if (r == 0)
Douglas Thompson079708b2007-07-19 01:49:58 -0700195 return (char *)ptr;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800196
Mauro Carvalho Chehab93e4fe62012-04-16 10:18:12 -0300197 *p += align - r;
198
Douglas Thompson7391c6d2007-07-19 01:50:21 -0700199 return (void *)(((unsigned long)ptr) + align - r);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800200}
201
Shaun Ruffellfaa2ad02012-09-22 20:26:38 -0500202static void _edac_mc_free(struct mem_ctl_info *mci)
203{
204 int i, chn, row;
205 struct csrow_info *csr;
206 const unsigned int tot_dimms = mci->tot_dimms;
207 const unsigned int tot_channels = mci->num_cschannel;
208 const unsigned int tot_csrows = mci->nr_csrows;
209
210 if (mci->dimms) {
211 for (i = 0; i < tot_dimms; i++)
212 kfree(mci->dimms[i]);
213 kfree(mci->dimms);
214 }
215 if (mci->csrows) {
216 for (row = 0; row < tot_csrows; row++) {
217 csr = mci->csrows[row];
218 if (csr) {
219 if (csr->channels) {
220 for (chn = 0; chn < tot_channels; chn++)
221 kfree(csr->channels[chn]);
222 kfree(csr->channels);
223 }
224 kfree(csr);
225 }
226 }
227 kfree(mci->csrows);
228 }
229 kfree(mci);
230}
231
Alan Coxda9bb1d2006-01-18 17:44:13 -0800232/**
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300233 * edac_mc_alloc: Allocate and partially fill a struct mem_ctl_info structure
234 * @mc_num: Memory controller number
235 * @n_layers: Number of MC hierarchy layers
236 * layers: Describes each layer as seen by the Memory Controller
237 * @size_pvt: size of private storage needed
238 *
Alan Coxda9bb1d2006-01-18 17:44:13 -0800239 *
240 * Everything is kmalloc'ed as one big chunk - more efficient.
241 * Only can be used if all structures have the same lifetime - otherwise
242 * you have to allocate and initialize your own structures.
243 *
244 * Use edac_mc_free() to free mc structures allocated by this function.
245 *
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300246 * NOTE: drivers handle multi-rank memories in different ways: in some
247 * drivers, one multi-rank memory stick is mapped as one entry, while, in
248 * others, a single multi-rank memory stick would be mapped into several
249 * entries. Currently, this function will allocate multiple struct dimm_info
250 * on such scenarios, as grouping the multiple ranks require drivers change.
251 *
Alan Coxda9bb1d2006-01-18 17:44:13 -0800252 * Returns:
Mauro Carvalho Chehabca0907b2012-05-02 14:37:00 -0300253 * On failure: NULL
254 * On success: struct mem_ctl_info pointer
Alan Coxda9bb1d2006-01-18 17:44:13 -0800255 */
Mauro Carvalho Chehabca0907b2012-05-02 14:37:00 -0300256struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
257 unsigned n_layers,
258 struct edac_mc_layer *layers,
259 unsigned sz_pvt)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800260{
261 struct mem_ctl_info *mci;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300262 struct edac_mc_layer *layer;
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300263 struct csrow_info *csr;
264 struct rank_info *chan;
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300265 struct dimm_info *dimm;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300266 u32 *ce_per_layer[EDAC_MAX_LAYERS], *ue_per_layer[EDAC_MAX_LAYERS];
267 unsigned pos[EDAC_MAX_LAYERS];
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300268 unsigned size, tot_dimms = 1, count = 1;
269 unsigned tot_csrows = 1, tot_channels = 1, tot_errcount = 0;
Mauro Carvalho Chehab5926ff52012-02-09 11:05:20 -0300270 void *pvt, *p, *ptr = NULL;
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300271 int i, j, row, chn, n, len, off;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300272 bool per_rank = false;
273
274 BUG_ON(n_layers > EDAC_MAX_LAYERS || n_layers == 0);
275 /*
276 * Calculate the total amount of dimms and csrows/cschannels while
277 * in the old API emulation mode
278 */
279 for (i = 0; i < n_layers; i++) {
280 tot_dimms *= layers[i].size;
281 if (layers[i].is_virt_csrow)
282 tot_csrows *= layers[i].size;
283 else
284 tot_channels *= layers[i].size;
285
286 if (layers[i].type == EDAC_MC_LAYER_CHIP_SELECT)
287 per_rank = true;
288 }
Alan Coxda9bb1d2006-01-18 17:44:13 -0800289
290 /* Figure out the offsets of the various items from the start of an mc
291 * structure. We want the alignment of each item to be at least as
292 * stringent as what the compiler would provide if we could simply
293 * hardcode everything into a single struct.
294 */
Mauro Carvalho Chehab93e4fe62012-04-16 10:18:12 -0300295 mci = edac_align_ptr(&ptr, sizeof(*mci), 1);
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300296 layer = edac_align_ptr(&ptr, sizeof(*layer), n_layers);
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300297 for (i = 0; i < n_layers; i++) {
298 count *= layers[i].size;
Joe Perches956b9ba2012-04-29 17:08:39 -0300299 edac_dbg(4, "errcount layer %d size %d\n", i, count);
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300300 ce_per_layer[i] = edac_align_ptr(&ptr, sizeof(u32), count);
301 ue_per_layer[i] = edac_align_ptr(&ptr, sizeof(u32), count);
302 tot_errcount += 2 * count;
303 }
304
Joe Perches956b9ba2012-04-29 17:08:39 -0300305 edac_dbg(4, "allocating %d error counters\n", tot_errcount);
Mauro Carvalho Chehab93e4fe62012-04-16 10:18:12 -0300306 pvt = edac_align_ptr(&ptr, sz_pvt, 1);
Douglas Thompson079708b2007-07-19 01:49:58 -0700307 size = ((unsigned long)pvt) + sz_pvt;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800308
Joe Perches956b9ba2012-04-29 17:08:39 -0300309 edac_dbg(1, "allocating %u bytes for mci data (%d %s, %d csrows/channels)\n",
310 size,
311 tot_dimms,
312 per_rank ? "ranks" : "dimms",
313 tot_csrows * tot_channels);
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300314
Doug Thompson8096cfa2007-07-19 01:50:27 -0700315 mci = kzalloc(size, GFP_KERNEL);
316 if (mci == NULL)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800317 return NULL;
318
319 /* Adjust pointers so they point within the memory we just allocated
320 * rather than an imaginary chunk of memory located at address 0.
321 */
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300322 layer = (struct edac_mc_layer *)(((char *)mci) + ((unsigned long)layer));
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300323 for (i = 0; i < n_layers; i++) {
324 mci->ce_per_layer[i] = (u32 *)((char *)mci + ((unsigned long)ce_per_layer[i]));
325 mci->ue_per_layer[i] = (u32 *)((char *)mci + ((unsigned long)ue_per_layer[i]));
326 }
Douglas Thompson079708b2007-07-19 01:49:58 -0700327 pvt = sz_pvt ? (((char *)mci) + ((unsigned long)pvt)) : NULL;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800328
Doug Thompsonb8f6f972007-07-19 01:50:26 -0700329 /* setup index and various internal pointers */
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300330 mci->mc_idx = mc_num;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300331 mci->tot_dimms = tot_dimms;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800332 mci->pvt_info = pvt;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300333 mci->n_layers = n_layers;
334 mci->layers = layer;
335 memcpy(mci->layers, layers, sizeof(*layer) * n_layers);
336 mci->nr_csrows = tot_csrows;
337 mci->num_cschannel = tot_channels;
338 mci->mem_is_per_rank = per_rank;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800339
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300340 /*
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300341 * Alocate and fill the csrow/channels structs
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300342 */
Joe Perchesd3d09e12013-01-26 11:24:00 -0800343 mci->csrows = kcalloc(tot_csrows, sizeof(*mci->csrows), GFP_KERNEL);
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300344 if (!mci->csrows)
345 goto error;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300346 for (row = 0; row < tot_csrows; row++) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300347 csr = kzalloc(sizeof(**mci->csrows), GFP_KERNEL);
348 if (!csr)
349 goto error;
350 mci->csrows[row] = csr;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300351 csr->csrow_idx = row;
352 csr->mci = mci;
353 csr->nr_channels = tot_channels;
Joe Perchesd3d09e12013-01-26 11:24:00 -0800354 csr->channels = kcalloc(tot_channels, sizeof(*csr->channels),
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300355 GFP_KERNEL);
356 if (!csr->channels)
357 goto error;
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300358
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300359 for (chn = 0; chn < tot_channels; chn++) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300360 chan = kzalloc(sizeof(**csr->channels), GFP_KERNEL);
361 if (!chan)
362 goto error;
363 csr->channels[chn] = chan;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800364 chan->chan_idx = chn;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300365 chan->csrow = csr;
366 }
367 }
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300368
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300369 /*
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300370 * Allocate and fill the dimm structs
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300371 */
Joe Perchesd3d09e12013-01-26 11:24:00 -0800372 mci->dimms = kcalloc(tot_dimms, sizeof(*mci->dimms), GFP_KERNEL);
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300373 if (!mci->dimms)
374 goto error;
375
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300376 memset(&pos, 0, sizeof(pos));
377 row = 0;
378 chn = 0;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300379 for (i = 0; i < tot_dimms; i++) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300380 chan = mci->csrows[row]->channels[chn];
381 off = EDAC_DIMM_OFF(layer, n_layers, pos[0], pos[1], pos[2]);
382 if (off < 0 || off >= tot_dimms) {
383 edac_mc_printk(mci, KERN_ERR, "EDAC core bug: EDAC_DIMM_OFF is trying to do an illegal data access\n");
384 goto error;
385 }
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300386
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300387 dimm = kzalloc(sizeof(**mci->dimms), GFP_KERNEL);
Dan Carpenter08a4a132012-05-18 15:51:02 +0300388 if (!dimm)
389 goto error;
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300390 mci->dimms[off] = dimm;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300391 dimm->mci = mci;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300392
Mauro Carvalho Chehab5926ff52012-02-09 11:05:20 -0300393 /*
394 * Copy DIMM location and initialize it.
395 */
396 len = sizeof(dimm->label);
397 p = dimm->label;
398 n = snprintf(p, len, "mc#%u", mc_num);
399 p += n;
400 len -= n;
401 for (j = 0; j < n_layers; j++) {
402 n = snprintf(p, len, "%s#%u",
403 edac_layer_name[layers[j].type],
404 pos[j]);
405 p += n;
406 len -= n;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300407 dimm->location[j] = pos[j];
408
Mauro Carvalho Chehab5926ff52012-02-09 11:05:20 -0300409 if (len <= 0)
410 break;
411 }
412
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300413 /* Link it to the csrows old API data */
414 chan->dimm = dimm;
415 dimm->csrow = row;
416 dimm->cschannel = chn;
417
418 /* Increment csrow location */
Mauro Carvalho Chehab24bef662012-10-24 10:30:01 -0200419 if (layers[0].is_virt_csrow) {
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300420 chn++;
Mauro Carvalho Chehab24bef662012-10-24 10:30:01 -0200421 if (chn == tot_channels) {
422 chn = 0;
423 row++;
424 }
425 } else {
426 row++;
427 if (row == tot_csrows) {
428 row = 0;
429 chn++;
430 }
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300431 }
432
433 /* Increment dimm location */
434 for (j = n_layers - 1; j >= 0; j--) {
435 pos[j]++;
436 if (pos[j] < layers[j].size)
437 break;
438 pos[j] = 0;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800439 }
440 }
441
Dave Jiang81d87cb2007-07-19 01:49:52 -0700442 mci->op_state = OP_ALLOC;
Doug Thompson8096cfa2007-07-19 01:50:27 -0700443
444 /* at this point, the root kobj is valid, and in order to
445 * 'free' the object, then the function:
446 * edac_mc_unregister_sysfs_main_kobj() must be called
447 * which will perform kobj unregistration and the actual free
448 * will occur during the kobject callback operation
449 */
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -0300450
Alan Coxda9bb1d2006-01-18 17:44:13 -0800451 return mci;
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300452
453error:
Shaun Ruffellfaa2ad02012-09-22 20:26:38 -0500454 _edac_mc_free(mci);
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300455
456 return NULL;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800457}
Dave Peterson91105402006-03-26 01:38:55 -0800458EXPORT_SYMBOL_GPL(edac_mc_alloc);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800459
Alan Coxda9bb1d2006-01-18 17:44:13 -0800460/**
Doug Thompson8096cfa2007-07-19 01:50:27 -0700461 * edac_mc_free
462 * 'Free' a previously allocated 'mci' structure
Alan Coxda9bb1d2006-01-18 17:44:13 -0800463 * @mci: pointer to a struct mem_ctl_info structure
Alan Coxda9bb1d2006-01-18 17:44:13 -0800464 */
465void edac_mc_free(struct mem_ctl_info *mci)
466{
Joe Perches956b9ba2012-04-29 17:08:39 -0300467 edac_dbg(1, "\n");
Mauro Carvalho Chehabbbc560a2010-08-16 18:22:43 -0300468
Shaun Ruffellfaa2ad02012-09-22 20:26:38 -0500469 /* If we're not yet registered with sysfs free only what was allocated
470 * in edac_mc_alloc().
471 */
472 if (!device_is_registered(&mci->dev)) {
473 _edac_mc_free(mci);
474 return;
475 }
476
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300477 /* the mci instance is freed here, when the sysfs object is dropped */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300478 edac_unregister_sysfs(mci);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800479}
Dave Peterson91105402006-03-26 01:38:55 -0800480EXPORT_SYMBOL_GPL(edac_mc_free);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800481
Doug Thompsonbce19682007-07-26 10:41:14 -0700482
Mauro Carvalho Chehab939747bd2010-08-10 11:22:01 -0300483/**
Doug Thompsonbce19682007-07-26 10:41:14 -0700484 * find_mci_by_dev
485 *
486 * scan list of controllers looking for the one that manages
487 * the 'dev' device
Mauro Carvalho Chehab939747bd2010-08-10 11:22:01 -0300488 * @dev: pointer to a struct device related with the MCI
Doug Thompsonbce19682007-07-26 10:41:14 -0700489 */
Mauro Carvalho Chehab939747bd2010-08-10 11:22:01 -0300490struct mem_ctl_info *find_mci_by_dev(struct device *dev)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800491{
492 struct mem_ctl_info *mci;
493 struct list_head *item;
494
Joe Perches956b9ba2012-04-29 17:08:39 -0300495 edac_dbg(3, "\n");
Alan Coxda9bb1d2006-01-18 17:44:13 -0800496
497 list_for_each(item, &mc_devices) {
498 mci = list_entry(item, struct mem_ctl_info, link);
499
Mauro Carvalho Chehabfd687502012-03-16 07:44:18 -0300500 if (mci->pdev == dev)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800501 return mci;
502 }
503
504 return NULL;
505}
Mauro Carvalho Chehab939747bd2010-08-10 11:22:01 -0300506EXPORT_SYMBOL_GPL(find_mci_by_dev);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800507
Dave Jiang81d87cb2007-07-19 01:49:52 -0700508/*
509 * handler for EDAC to check if NMI type handler has asserted interrupt
510 */
511static int edac_mc_assert_error_check_and_clear(void)
512{
Dave Jiang66ee2f92007-07-19 01:49:54 -0700513 int old_state;
Dave Jiang81d87cb2007-07-19 01:49:52 -0700514
Douglas Thompson079708b2007-07-19 01:49:58 -0700515 if (edac_op_state == EDAC_OPSTATE_POLL)
Dave Jiang81d87cb2007-07-19 01:49:52 -0700516 return 1;
517
Dave Jiang66ee2f92007-07-19 01:49:54 -0700518 old_state = edac_err_assert;
519 edac_err_assert = 0;
Dave Jiang81d87cb2007-07-19 01:49:52 -0700520
Dave Jiang66ee2f92007-07-19 01:49:54 -0700521 return old_state;
Dave Jiang81d87cb2007-07-19 01:49:52 -0700522}
523
524/*
525 * edac_mc_workq_function
526 * performs the operation scheduled by a workq request
527 */
Dave Jiang81d87cb2007-07-19 01:49:52 -0700528static void edac_mc_workq_function(struct work_struct *work_req)
529{
Jean Delvarefbeb4382009-04-13 14:40:21 -0700530 struct delayed_work *d_work = to_delayed_work(work_req);
Dave Jiang81d87cb2007-07-19 01:49:52 -0700531 struct mem_ctl_info *mci = to_edac_mem_ctl_work(d_work);
Dave Jiang81d87cb2007-07-19 01:49:52 -0700532
533 mutex_lock(&mem_ctls_mutex);
534
Doug Thompsonbf52fa42007-07-19 01:50:30 -0700535 /* if this control struct has movd to offline state, we are done */
536 if (mci->op_state == OP_OFFLINE) {
537 mutex_unlock(&mem_ctls_mutex);
538 return;
539 }
540
Dave Jiang81d87cb2007-07-19 01:49:52 -0700541 /* Only poll controllers that are running polled and have a check */
542 if (edac_mc_assert_error_check_and_clear() && (mci->edac_check != NULL))
543 mci->edac_check(mci);
544
Dave Jiang81d87cb2007-07-19 01:49:52 -0700545 mutex_unlock(&mem_ctls_mutex);
546
547 /* Reschedule */
Dave Jiang4de78c62007-07-19 01:49:54 -0700548 queue_delayed_work(edac_workqueue, &mci->work,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700549 msecs_to_jiffies(edac_mc_get_poll_msec()));
Dave Jiang81d87cb2007-07-19 01:49:52 -0700550}
551
552/*
553 * edac_mc_workq_setup
554 * initialize a workq item for this mci
555 * passing in the new delay period in msec
Doug Thompsonbf52fa42007-07-19 01:50:30 -0700556 *
557 * locking model:
558 *
559 * called with the mem_ctls_mutex held
Dave Jiang81d87cb2007-07-19 01:49:52 -0700560 */
Doug Thompsonbf52fa42007-07-19 01:50:30 -0700561static void edac_mc_workq_setup(struct mem_ctl_info *mci, unsigned msec)
Dave Jiang81d87cb2007-07-19 01:49:52 -0700562{
Joe Perches956b9ba2012-04-29 17:08:39 -0300563 edac_dbg(0, "\n");
Dave Jiang81d87cb2007-07-19 01:49:52 -0700564
Doug Thompsonbf52fa42007-07-19 01:50:30 -0700565 /* if this instance is not in the POLL state, then simply return */
566 if (mci->op_state != OP_RUNNING_POLL)
567 return;
568
Dave Jiang81d87cb2007-07-19 01:49:52 -0700569 INIT_DELAYED_WORK(&mci->work, edac_mc_workq_function);
Tejun Heo41f63c52012-08-03 10:30:47 -0700570 mod_delayed_work(edac_workqueue, &mci->work, msecs_to_jiffies(msec));
Dave Jiang81d87cb2007-07-19 01:49:52 -0700571}
572
573/*
574 * edac_mc_workq_teardown
575 * stop the workq processing on this mci
Doug Thompsonbf52fa42007-07-19 01:50:30 -0700576 *
577 * locking model:
578 *
579 * called WITHOUT lock held
Dave Jiang81d87cb2007-07-19 01:49:52 -0700580 */
Doug Thompsonbf52fa42007-07-19 01:50:30 -0700581static void edac_mc_workq_teardown(struct mem_ctl_info *mci)
Dave Jiang81d87cb2007-07-19 01:49:52 -0700582{
583 int status;
584
Borislav Petkov00740c52010-09-26 12:42:23 +0200585 if (mci->op_state != OP_RUNNING_POLL)
586 return;
587
Doug Thompsonbce19682007-07-26 10:41:14 -0700588 status = cancel_delayed_work(&mci->work);
589 if (status == 0) {
Joe Perches956b9ba2012-04-29 17:08:39 -0300590 edac_dbg(0, "not canceled, flush the queue\n");
Doug Thompsonbf52fa42007-07-19 01:50:30 -0700591
Doug Thompsonbce19682007-07-26 10:41:14 -0700592 /* workq instance might be running, wait for it */
593 flush_workqueue(edac_workqueue);
Dave Jiang81d87cb2007-07-19 01:49:52 -0700594 }
595}
596
597/*
Doug Thompsonbce19682007-07-26 10:41:14 -0700598 * edac_mc_reset_delay_period(unsigned long value)
599 *
600 * user space has updated our poll period value, need to
601 * reset our workq delays
Dave Jiang81d87cb2007-07-19 01:49:52 -0700602 */
Doug Thompsonbce19682007-07-26 10:41:14 -0700603void edac_mc_reset_delay_period(int value)
Dave Jiang81d87cb2007-07-19 01:49:52 -0700604{
Doug Thompsonbce19682007-07-26 10:41:14 -0700605 struct mem_ctl_info *mci;
606 struct list_head *item;
Dave Jiang81d87cb2007-07-19 01:49:52 -0700607
Doug Thompsonbf52fa42007-07-19 01:50:30 -0700608 mutex_lock(&mem_ctls_mutex);
609
Doug Thompsonbce19682007-07-26 10:41:14 -0700610 list_for_each(item, &mc_devices) {
611 mci = list_entry(item, struct mem_ctl_info, link);
612
613 edac_mc_workq_setup(mci, (unsigned long) value);
614 }
Dave Jiang81d87cb2007-07-19 01:49:52 -0700615
616 mutex_unlock(&mem_ctls_mutex);
617}
618
Doug Thompsonbce19682007-07-26 10:41:14 -0700619
620
Doug Thompson2d7bbb92006-06-30 01:56:08 -0700621/* Return 0 on success, 1 on failure.
622 * Before calling this function, caller must
623 * assign a unique value to mci->mc_idx.
Doug Thompsonbf52fa42007-07-19 01:50:30 -0700624 *
625 * locking model:
626 *
627 * called with the mem_ctls_mutex lock held
Doug Thompson2d7bbb92006-06-30 01:56:08 -0700628 */
Douglas Thompson079708b2007-07-19 01:49:58 -0700629static int add_mc_to_global_list(struct mem_ctl_info *mci)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800630{
631 struct list_head *item, *insert_before;
632 struct mem_ctl_info *p;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800633
Doug Thompson2d7bbb92006-06-30 01:56:08 -0700634 insert_before = &mc_devices;
635
Mauro Carvalho Chehabfd687502012-03-16 07:44:18 -0300636 p = find_mci_by_dev(mci->pdev);
Doug Thompsonbf52fa42007-07-19 01:50:30 -0700637 if (unlikely(p != NULL))
Doug Thompson2d7bbb92006-06-30 01:56:08 -0700638 goto fail0;
639
640 list_for_each(item, &mc_devices) {
641 p = list_entry(item, struct mem_ctl_info, link);
642
643 if (p->mc_idx >= mci->mc_idx) {
644 if (unlikely(p->mc_idx == mci->mc_idx))
645 goto fail1;
646
647 insert_before = item;
648 break;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800649 }
Alan Coxda9bb1d2006-01-18 17:44:13 -0800650 }
651
652 list_add_tail_rcu(&mci->link, insert_before);
Dave Jiangc0d12172007-07-19 01:49:46 -0700653 atomic_inc(&edac_handlers);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800654 return 0;
Doug Thompson2d7bbb92006-06-30 01:56:08 -0700655
Douglas Thompson052dfb42007-07-19 01:50:13 -0700656fail0:
Doug Thompson2d7bbb92006-06-30 01:56:08 -0700657 edac_printk(KERN_WARNING, EDAC_MC,
Mauro Carvalho Chehabfd687502012-03-16 07:44:18 -0300658 "%s (%s) %s %s already assigned %d\n", dev_name(p->pdev),
Stephen Rothwell17aa7e02008-05-05 13:54:19 +1000659 edac_dev_name(mci), p->mod_name, p->ctl_name, p->mc_idx);
Doug Thompson2d7bbb92006-06-30 01:56:08 -0700660 return 1;
661
Douglas Thompson052dfb42007-07-19 01:50:13 -0700662fail1:
Doug Thompson2d7bbb92006-06-30 01:56:08 -0700663 edac_printk(KERN_WARNING, EDAC_MC,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700664 "bug in low-level driver: attempt to assign\n"
665 " duplicate mc_idx %d in %s()\n", p->mc_idx, __func__);
Doug Thompson2d7bbb92006-06-30 01:56:08 -0700666 return 1;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800667}
668
Dave Petersone7ecd892006-03-26 01:38:52 -0800669static void del_mc_from_global_list(struct mem_ctl_info *mci)
Dave Petersona1d03fc2006-03-26 01:38:46 -0800670{
Dave Jiangc0d12172007-07-19 01:49:46 -0700671 atomic_dec(&edac_handlers);
Dave Petersona1d03fc2006-03-26 01:38:46 -0800672 list_del_rcu(&mci->link);
Lai Jiangshane2e77092011-05-26 16:25:58 -0700673
674 /* these are for safe removal of devices from global list while
675 * NMI handlers may be traversing list
676 */
677 synchronize_rcu();
678 INIT_LIST_HEAD(&mci->link);
Dave Petersona1d03fc2006-03-26 01:38:46 -0800679}
680
Alan Coxda9bb1d2006-01-18 17:44:13 -0800681/**
Douglas Thompson5da08312007-07-19 01:49:31 -0700682 * edac_mc_find: Search for a mem_ctl_info structure whose index is 'idx'.
683 *
684 * If found, return a pointer to the structure.
685 * Else return NULL.
686 *
687 * Caller must hold mem_ctls_mutex.
688 */
Douglas Thompson079708b2007-07-19 01:49:58 -0700689struct mem_ctl_info *edac_mc_find(int idx)
Douglas Thompson5da08312007-07-19 01:49:31 -0700690{
691 struct list_head *item;
692 struct mem_ctl_info *mci;
693
694 list_for_each(item, &mc_devices) {
695 mci = list_entry(item, struct mem_ctl_info, link);
696
697 if (mci->mc_idx >= idx) {
698 if (mci->mc_idx == idx)
699 return mci;
700
701 break;
702 }
703 }
704
705 return NULL;
706}
707EXPORT_SYMBOL(edac_mc_find);
708
709/**
Dave Peterson472678e2006-03-26 01:38:49 -0800710 * edac_mc_add_mc: Insert the 'mci' structure into the mci global list and
711 * create sysfs entries associated with mci structure
Alan Coxda9bb1d2006-01-18 17:44:13 -0800712 * @mci: pointer to the mci structure to be added to the list
713 *
714 * Return:
715 * 0 Success
716 * !0 Failure
717 */
718
719/* FIXME - should a warning be printed if no error detection? correction? */
Doug Thompsonb8f6f972007-07-19 01:50:26 -0700720int edac_mc_add_mc(struct mem_ctl_info *mci)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800721{
Joe Perches956b9ba2012-04-29 17:08:39 -0300722 edac_dbg(0, "\n");
Doug Thompsonb8f6f972007-07-19 01:50:26 -0700723
Alan Coxda9bb1d2006-01-18 17:44:13 -0800724#ifdef CONFIG_EDAC_DEBUG
725 if (edac_debug_level >= 3)
726 edac_mc_dump_mci(mci);
Dave Petersone7ecd892006-03-26 01:38:52 -0800727
Alan Coxda9bb1d2006-01-18 17:44:13 -0800728 if (edac_debug_level >= 4) {
729 int i;
730
731 for (i = 0; i < mci->nr_csrows; i++) {
Mauro Carvalho Chehab6e84d352012-04-30 10:24:43 -0300732 struct csrow_info *csrow = mci->csrows[i];
733 u32 nr_pages = 0;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800734 int j;
Dave Petersone7ecd892006-03-26 01:38:52 -0800735
Mauro Carvalho Chehab6e84d352012-04-30 10:24:43 -0300736 for (j = 0; j < csrow->nr_channels; j++)
737 nr_pages += csrow->channels[j]->dimm->nr_pages;
738 if (!nr_pages)
739 continue;
740 edac_mc_dump_csrow(csrow);
741 for (j = 0; j < csrow->nr_channels; j++)
742 if (csrow->channels[j]->dimm->nr_pages)
743 edac_mc_dump_channel(csrow->channels[j]);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800744 }
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300745 for (i = 0; i < mci->tot_dimms; i++)
Mauro Carvalho Chehab6e84d352012-04-30 10:24:43 -0300746 if (mci->dimms[i]->nr_pages)
747 edac_mc_dump_dimm(mci->dimms[i], i);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800748 }
749#endif
Matthias Kaehlcke63b7df92007-07-19 01:49:38 -0700750 mutex_lock(&mem_ctls_mutex);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800751
752 if (add_mc_to_global_list(mci))
Dave Peterson028a7b62006-03-26 01:38:47 -0800753 goto fail0;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800754
755 /* set load time so that error rate can be tracked */
756 mci->start_time = jiffies;
757
eric wollesen9794f332007-02-12 00:53:08 -0800758 if (edac_create_sysfs_mci_device(mci)) {
759 edac_mc_printk(mci, KERN_WARNING,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700760 "failed to create sysfs device\n");
eric wollesen9794f332007-02-12 00:53:08 -0800761 goto fail1;
762 }
Alan Coxda9bb1d2006-01-18 17:44:13 -0800763
Dave Jiang81d87cb2007-07-19 01:49:52 -0700764 /* If there IS a check routine, then we are running POLLED */
765 if (mci->edac_check != NULL) {
766 /* This instance is NOW RUNNING */
767 mci->op_state = OP_RUNNING_POLL;
768
769 edac_mc_workq_setup(mci, edac_mc_get_poll_msec());
770 } else {
771 mci->op_state = OP_RUNNING_INTERRUPT;
772 }
773
Alan Coxda9bb1d2006-01-18 17:44:13 -0800774 /* Report action taken */
Doug Thompsonbf52fa42007-07-19 01:50:30 -0700775 edac_mc_printk(mci, KERN_INFO, "Giving out device to '%s' '%s':"
Stephen Rothwell17aa7e02008-05-05 13:54:19 +1000776 " DEV %s\n", mci->mod_name, mci->ctl_name, edac_dev_name(mci));
Alan Coxda9bb1d2006-01-18 17:44:13 -0800777
Matthias Kaehlcke63b7df92007-07-19 01:49:38 -0700778 mutex_unlock(&mem_ctls_mutex);
Dave Peterson028a7b62006-03-26 01:38:47 -0800779 return 0;
780
Douglas Thompson052dfb42007-07-19 01:50:13 -0700781fail1:
Dave Peterson028a7b62006-03-26 01:38:47 -0800782 del_mc_from_global_list(mci);
783
Douglas Thompson052dfb42007-07-19 01:50:13 -0700784fail0:
Matthias Kaehlcke63b7df92007-07-19 01:49:38 -0700785 mutex_unlock(&mem_ctls_mutex);
Dave Peterson028a7b62006-03-26 01:38:47 -0800786 return 1;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800787}
Dave Peterson91105402006-03-26 01:38:55 -0800788EXPORT_SYMBOL_GPL(edac_mc_add_mc);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800789
Alan Coxda9bb1d2006-01-18 17:44:13 -0800790/**
Dave Peterson472678e2006-03-26 01:38:49 -0800791 * edac_mc_del_mc: Remove sysfs entries for specified mci structure and
792 * remove mci structure from global list
Doug Thompson37f04582006-06-30 01:56:07 -0700793 * @pdev: Pointer to 'struct device' representing mci structure to remove.
Alan Coxda9bb1d2006-01-18 17:44:13 -0800794 *
Dave Peterson18dbc332006-03-26 01:38:50 -0800795 * Return pointer to removed mci structure, or NULL if device not found.
Alan Coxda9bb1d2006-01-18 17:44:13 -0800796 */
Douglas Thompson079708b2007-07-19 01:49:58 -0700797struct mem_ctl_info *edac_mc_del_mc(struct device *dev)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800798{
Dave Peterson18dbc332006-03-26 01:38:50 -0800799 struct mem_ctl_info *mci;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800800
Joe Perches956b9ba2012-04-29 17:08:39 -0300801 edac_dbg(0, "\n");
Doug Thompsonbf52fa42007-07-19 01:50:30 -0700802
Matthias Kaehlcke63b7df92007-07-19 01:49:38 -0700803 mutex_lock(&mem_ctls_mutex);
Dave Peterson18dbc332006-03-26 01:38:50 -0800804
Doug Thompsonbf52fa42007-07-19 01:50:30 -0700805 /* find the requested mci struct in the global list */
806 mci = find_mci_by_dev(dev);
807 if (mci == NULL) {
Matthias Kaehlcke63b7df92007-07-19 01:49:38 -0700808 mutex_unlock(&mem_ctls_mutex);
Dave Peterson18dbc332006-03-26 01:38:50 -0800809 return NULL;
810 }
811
Alan Coxda9bb1d2006-01-18 17:44:13 -0800812 del_mc_from_global_list(mci);
Matthias Kaehlcke63b7df92007-07-19 01:49:38 -0700813 mutex_unlock(&mem_ctls_mutex);
Doug Thompsonbf52fa42007-07-19 01:50:30 -0700814
Borislav Petkovbb31b3122010-12-02 17:48:35 +0100815 /* flush workq processes */
Doug Thompsonbf52fa42007-07-19 01:50:30 -0700816 edac_mc_workq_teardown(mci);
Borislav Petkovbb31b3122010-12-02 17:48:35 +0100817
818 /* marking MCI offline */
819 mci->op_state = OP_OFFLINE;
820
821 /* remove from sysfs */
Doug Thompsonbf52fa42007-07-19 01:50:30 -0700822 edac_remove_sysfs_mci_device(mci);
823
Dave Peterson537fba22006-03-26 01:38:40 -0800824 edac_printk(KERN_INFO, EDAC_MC,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700825 "Removed device %d for %s %s: DEV %s\n", mci->mc_idx,
Stephen Rothwell17aa7e02008-05-05 13:54:19 +1000826 mci->mod_name, mci->ctl_name, edac_dev_name(mci));
Doug Thompsonbf52fa42007-07-19 01:50:30 -0700827
Dave Peterson18dbc332006-03-26 01:38:50 -0800828 return mci;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800829}
Dave Peterson91105402006-03-26 01:38:55 -0800830EXPORT_SYMBOL_GPL(edac_mc_del_mc);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800831
Adrian Bunk2da1c112007-07-19 01:49:32 -0700832static void edac_mc_scrub_block(unsigned long page, unsigned long offset,
833 u32 size)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800834{
835 struct page *pg;
836 void *virt_addr;
837 unsigned long flags = 0;
838
Joe Perches956b9ba2012-04-29 17:08:39 -0300839 edac_dbg(3, "\n");
Alan Coxda9bb1d2006-01-18 17:44:13 -0800840
841 /* ECC error page was not in our memory. Ignore it. */
Douglas Thompson079708b2007-07-19 01:49:58 -0700842 if (!pfn_valid(page))
Alan Coxda9bb1d2006-01-18 17:44:13 -0800843 return;
844
845 /* Find the actual page structure then map it and fix */
846 pg = pfn_to_page(page);
847
848 if (PageHighMem(pg))
849 local_irq_save(flags);
850
Cong Wang4e5df7c2011-11-25 23:14:19 +0800851 virt_addr = kmap_atomic(pg);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800852
853 /* Perform architecture specific atomic scrub operation */
854 atomic_scrub(virt_addr + offset, size);
855
856 /* Unmap and complete */
Cong Wang4e5df7c2011-11-25 23:14:19 +0800857 kunmap_atomic(virt_addr);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800858
859 if (PageHighMem(pg))
860 local_irq_restore(flags);
861}
862
Alan Coxda9bb1d2006-01-18 17:44:13 -0800863/* FIXME - should return -1 */
Dave Petersone7ecd892006-03-26 01:38:52 -0800864int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci, unsigned long page)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800865{
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300866 struct csrow_info **csrows = mci->csrows;
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300867 int row, i, j, n;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800868
Joe Perches956b9ba2012-04-29 17:08:39 -0300869 edac_dbg(1, "MC%d: 0x%lx\n", mci->mc_idx, page);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800870 row = -1;
871
872 for (i = 0; i < mci->nr_csrows; i++) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300873 struct csrow_info *csrow = csrows[i];
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300874 n = 0;
875 for (j = 0; j < csrow->nr_channels; j++) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300876 struct dimm_info *dimm = csrow->channels[j]->dimm;
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300877 n += dimm->nr_pages;
878 }
879 if (n == 0)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800880 continue;
881
Joe Perches956b9ba2012-04-29 17:08:39 -0300882 edac_dbg(3, "MC%d: first(0x%lx) page(0x%lx) last(0x%lx) mask(0x%lx)\n",
883 mci->mc_idx,
884 csrow->first_page, page, csrow->last_page,
885 csrow->page_mask);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800886
887 if ((page >= csrow->first_page) &&
888 (page <= csrow->last_page) &&
889 ((page & csrow->page_mask) ==
890 (csrow->first_page & csrow->page_mask))) {
891 row = i;
892 break;
893 }
894 }
895
896 if (row == -1)
Dave Peterson537fba22006-03-26 01:38:40 -0800897 edac_mc_printk(mci, KERN_ERR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700898 "could not look up page error address %lx\n",
899 (unsigned long)page);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800900
901 return row;
902}
Dave Peterson91105402006-03-26 01:38:55 -0800903EXPORT_SYMBOL_GPL(edac_mc_find_csrow_by_page);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800904
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300905const char *edac_layer_name[] = {
906 [EDAC_MC_LAYER_BRANCH] = "branch",
907 [EDAC_MC_LAYER_CHANNEL] = "channel",
908 [EDAC_MC_LAYER_SLOT] = "slot",
909 [EDAC_MC_LAYER_CHIP_SELECT] = "csrow",
910};
911EXPORT_SYMBOL_GPL(edac_layer_name);
912
913static void edac_inc_ce_error(struct mem_ctl_info *mci,
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -0300914 bool enable_per_layer_report,
915 const int pos[EDAC_MAX_LAYERS],
916 const u16 count)
Alan Coxda9bb1d2006-01-18 17:44:13 -0800917{
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300918 int i, index = 0;
Alan Coxda9bb1d2006-01-18 17:44:13 -0800919
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -0300920 mci->ce_mc += count;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300921
922 if (!enable_per_layer_report) {
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -0300923 mci->ce_noinfo_count += count;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300924 return;
925 }
926
927 for (i = 0; i < mci->n_layers; i++) {
928 if (pos[i] < 0)
929 break;
930 index += pos[i];
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -0300931 mci->ce_per_layer[i][index] += count;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300932
933 if (i < mci->n_layers - 1)
934 index *= mci->layers[i + 1].size;
935 }
936}
937
938static void edac_inc_ue_error(struct mem_ctl_info *mci,
939 bool enable_per_layer_report,
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -0300940 const int pos[EDAC_MAX_LAYERS],
941 const u16 count)
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300942{
943 int i, index = 0;
944
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -0300945 mci->ue_mc += count;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300946
947 if (!enable_per_layer_report) {
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -0300948 mci->ce_noinfo_count += count;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300949 return;
950 }
951
952 for (i = 0; i < mci->n_layers; i++) {
953 if (pos[i] < 0)
954 break;
955 index += pos[i];
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -0300956 mci->ue_per_layer[i][index] += count;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300957
958 if (i < mci->n_layers - 1)
959 index *= mci->layers[i + 1].size;
960 }
961}
962
963static void edac_ce_error(struct mem_ctl_info *mci,
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -0300964 const u16 error_count,
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300965 const int pos[EDAC_MAX_LAYERS],
966 const char *msg,
967 const char *location,
968 const char *label,
969 const char *detail,
970 const char *other_detail,
971 const bool enable_per_layer_report,
972 const unsigned long page_frame_number,
973 const unsigned long offset_in_page,
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -0300974 long grain)
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300975{
976 unsigned long remapped_page;
Borislav Petkovf430d572012-09-10 18:36:09 +0200977 char *msg_aux = "";
978
979 if (*msg)
980 msg_aux = " ";
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300981
982 if (edac_mc_get_log_ce()) {
983 if (other_detail && *other_detail)
984 edac_mc_printk(mci, KERN_WARNING,
Borislav Petkovf430d572012-09-10 18:36:09 +0200985 "%d CE %s%son %s (%s %s - %s)\n",
986 error_count, msg, msg_aux, label,
987 location, detail, other_detail);
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300988 else
989 edac_mc_printk(mci, KERN_WARNING,
Borislav Petkovf430d572012-09-10 18:36:09 +0200990 "%d CE %s%son %s (%s %s)\n",
991 error_count, msg, msg_aux, label,
992 location, detail);
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300993 }
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -0300994 edac_inc_ce_error(mci, enable_per_layer_report, pos, error_count);
Alan Coxda9bb1d2006-01-18 17:44:13 -0800995
996 if (mci->scrub_mode & SCRUB_SW_SRC) {
997 /*
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300998 * Some memory controllers (called MCs below) can remap
999 * memory so that it is still available at a different
1000 * address when PCI devices map into memory.
1001 * MC's that can't do this, lose the memory where PCI
1002 * devices are mapped. This mapping is MC-dependent
1003 * and so we call back into the MC driver for it to
1004 * map the MC page to a physical (CPU) page which can
1005 * then be mapped to a virtual page - which can then
1006 * be scrubbed.
1007 */
Alan Coxda9bb1d2006-01-18 17:44:13 -08001008 remapped_page = mci->ctl_page_to_phys ?
Douglas Thompson052dfb42007-07-19 01:50:13 -07001009 mci->ctl_page_to_phys(mci, page_frame_number) :
1010 page_frame_number;
Alan Coxda9bb1d2006-01-18 17:44:13 -08001011
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001012 edac_mc_scrub_block(remapped_page,
1013 offset_in_page, grain);
Alan Coxda9bb1d2006-01-18 17:44:13 -08001014 }
1015}
1016
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001017static void edac_ue_error(struct mem_ctl_info *mci,
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -03001018 const u16 error_count,
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001019 const int pos[EDAC_MAX_LAYERS],
1020 const char *msg,
1021 const char *location,
1022 const char *label,
1023 const char *detail,
1024 const char *other_detail,
1025 const bool enable_per_layer_report)
Alan Coxda9bb1d2006-01-18 17:44:13 -08001026{
Borislav Petkovf430d572012-09-10 18:36:09 +02001027 char *msg_aux = "";
1028
1029 if (*msg)
1030 msg_aux = " ";
1031
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001032 if (edac_mc_get_log_ue()) {
1033 if (other_detail && *other_detail)
1034 edac_mc_printk(mci, KERN_WARNING,
Borislav Petkovf430d572012-09-10 18:36:09 +02001035 "%d UE %s%son %s (%s %s - %s)\n",
1036 error_count, msg, msg_aux, label,
1037 location, detail, other_detail);
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001038 else
1039 edac_mc_printk(mci, KERN_WARNING,
Borislav Petkovf430d572012-09-10 18:36:09 +02001040 "%d UE %s%son %s (%s %s)\n",
1041 error_count, msg, msg_aux, label,
1042 location, detail);
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001043 }
Dave Petersone7ecd892006-03-26 01:38:52 -08001044
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001045 if (edac_mc_get_panic_on_ue()) {
1046 if (other_detail && *other_detail)
Borislav Petkovf430d572012-09-10 18:36:09 +02001047 panic("UE %s%son %s (%s%s - %s)\n",
1048 msg, msg_aux, label, location, detail, other_detail);
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001049 else
Borislav Petkovf430d572012-09-10 18:36:09 +02001050 panic("UE %s%son %s (%s%s)\n",
1051 msg, msg_aux, label, location, detail);
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001052 }
1053
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -03001054 edac_inc_ue_error(mci, enable_per_layer_report, pos, error_count);
Alan Coxda9bb1d2006-01-18 17:44:13 -08001055}
1056
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001057#define OTHER_LABEL " or "
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -03001058
1059/**
1060 * edac_mc_handle_error - reports a memory event to userspace
1061 *
1062 * @type: severity of the error (CE/UE/Fatal)
1063 * @mci: a struct mem_ctl_info pointer
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -03001064 * @error_count: Number of errors of the same type
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -03001065 * @page_frame_number: mem page where the error occurred
1066 * @offset_in_page: offset of the error inside the page
1067 * @syndrome: ECC syndrome
1068 * @top_layer: Memory layer[0] position
1069 * @mid_layer: Memory layer[1] position
1070 * @low_layer: Memory layer[2] position
1071 * @msg: Message meaningful to the end users that
1072 * explains the event
1073 * @other_detail: Technical details about the event that
1074 * may help hardware manufacturers and
1075 * EDAC developers to analyse the event
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -03001076 */
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001077void edac_mc_handle_error(const enum hw_event_mc_err_type type,
1078 struct mem_ctl_info *mci,
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -03001079 const u16 error_count,
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001080 const unsigned long page_frame_number,
1081 const unsigned long offset_in_page,
1082 const unsigned long syndrome,
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -03001083 const int top_layer,
1084 const int mid_layer,
1085 const int low_layer,
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001086 const char *msg,
Mauro Carvalho Chehab03f7eae2012-06-04 11:29:25 -03001087 const char *other_detail)
Alan Coxda9bb1d2006-01-18 17:44:13 -08001088{
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001089 /* FIXME: too much for stack: move it to some pre-alocated area */
1090 char detail[80], location[80];
1091 char label[(EDAC_MC_LABEL_LEN + 1 + sizeof(OTHER_LABEL)) * mci->tot_dimms];
1092 char *p;
1093 int row = -1, chan = -1;
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -03001094 int pos[EDAC_MAX_LAYERS] = { top_layer, mid_layer, low_layer };
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001095 int i;
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -03001096 long grain;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001097 bool enable_per_layer_report = false;
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -03001098 u8 grain_bits;
Alan Coxda9bb1d2006-01-18 17:44:13 -08001099
Joe Perches956b9ba2012-04-29 17:08:39 -03001100 edac_dbg(3, "MC%d\n", mci->mc_idx);
Alan Coxda9bb1d2006-01-18 17:44:13 -08001101
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001102 /*
1103 * Check if the event report is consistent and if the memory
1104 * location is known. If it is known, enable_per_layer_report will be
1105 * true, the DIMM(s) label info will be filled and the per-layer
1106 * error counters will be incremented.
1107 */
1108 for (i = 0; i < mci->n_layers; i++) {
1109 if (pos[i] >= (int)mci->layers[i].size) {
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001110
1111 edac_mc_printk(mci, KERN_ERR,
1112 "INTERNAL ERROR: %s value is out of range (%d >= %d)\n",
1113 edac_layer_name[mci->layers[i].type],
1114 pos[i], mci->layers[i].size);
1115 /*
1116 * Instead of just returning it, let's use what's
1117 * known about the error. The increment routines and
1118 * the DIMM filter logic will do the right thing by
1119 * pointing the likely damaged DIMMs.
1120 */
1121 pos[i] = -1;
1122 }
1123 if (pos[i] >= 0)
1124 enable_per_layer_report = true;
Alan Coxda9bb1d2006-01-18 17:44:13 -08001125 }
1126
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001127 /*
1128 * Get the dimm label/grain that applies to the match criteria.
1129 * As the error algorithm may not be able to point to just one memory
1130 * stick, the logic here will get all possible labels that could
1131 * pottentially be affected by the error.
1132 * On FB-DIMM memory controllers, for uncorrected errors, it is common
1133 * to have only the MC channel and the MC dimm (also called "branch")
1134 * but the channel is not known, as the memory is arranged in pairs,
1135 * where each memory belongs to a separate channel within the same
1136 * branch.
1137 */
1138 grain = 0;
1139 p = label;
1140 *p = '\0';
Borislav Petkov4da1b7b2012-09-10 17:57:44 +02001141
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001142 for (i = 0; i < mci->tot_dimms; i++) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001143 struct dimm_info *dimm = mci->dimms[i];
Dave Petersone7ecd892006-03-26 01:38:52 -08001144
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -03001145 if (top_layer >= 0 && top_layer != dimm->location[0])
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001146 continue;
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -03001147 if (mid_layer >= 0 && mid_layer != dimm->location[1])
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001148 continue;
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -03001149 if (low_layer >= 0 && low_layer != dimm->location[2])
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001150 continue;
1151
1152 /* get the max grain, over the error match range */
1153 if (dimm->grain > grain)
1154 grain = dimm->grain;
1155
1156 /*
1157 * If the error is memory-controller wide, there's no need to
1158 * seek for the affected DIMMs because the whole
1159 * channel/memory controller/... may be affected.
1160 * Also, don't show errors for empty DIMM slots.
1161 */
1162 if (enable_per_layer_report && dimm->nr_pages) {
1163 if (p != label) {
1164 strcpy(p, OTHER_LABEL);
1165 p += strlen(OTHER_LABEL);
1166 }
1167 strcpy(p, dimm->label);
1168 p += strlen(p);
1169 *p = '\0';
1170
1171 /*
1172 * get csrow/channel of the DIMM, in order to allow
1173 * incrementing the compat API counters
1174 */
Joe Perches956b9ba2012-04-29 17:08:39 -03001175 edac_dbg(4, "%s csrows map: (%d,%d)\n",
1176 mci->mem_is_per_rank ? "rank" : "dimm",
1177 dimm->csrow, dimm->cschannel);
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001178 if (row == -1)
1179 row = dimm->csrow;
1180 else if (row >= 0 && row != dimm->csrow)
1181 row = -2;
1182
1183 if (chan == -1)
1184 chan = dimm->cschannel;
1185 else if (chan >= 0 && chan != dimm->cschannel)
1186 chan = -2;
1187 }
Alan Coxda9bb1d2006-01-18 17:44:13 -08001188 }
1189
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001190 if (!enable_per_layer_report) {
1191 strcpy(label, "any memory");
1192 } else {
Joe Perches956b9ba2012-04-29 17:08:39 -03001193 edac_dbg(4, "csrow/channel to increment: (%d,%d)\n", row, chan);
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001194 if (p == label)
1195 strcpy(label, "unknown memory");
1196 if (type == HW_EVENT_ERR_CORRECTED) {
1197 if (row >= 0) {
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -03001198 mci->csrows[row]->ce_count += error_count;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001199 if (chan >= 0)
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -03001200 mci->csrows[row]->channels[chan]->ce_count += error_count;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001201 }
1202 } else
1203 if (row >= 0)
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -03001204 mci->csrows[row]->ue_count += error_count;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001205 }
Alan Coxda9bb1d2006-01-18 17:44:13 -08001206
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001207 /* Fill the RAM location data */
1208 p = location;
Borislav Petkov4da1b7b2012-09-10 17:57:44 +02001209
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001210 for (i = 0; i < mci->n_layers; i++) {
1211 if (pos[i] < 0)
1212 continue;
1213
1214 p += sprintf(p, "%s:%d ",
1215 edac_layer_name[mci->layers[i].type],
1216 pos[i]);
1217 }
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -03001218 if (p > location)
1219 *(p - 1) = '\0';
1220
1221 /* Report the error via the trace interface */
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -03001222 grain_bits = fls_long(grain) + 1;
1223 trace_mc_event(type, msg, label, error_count,
1224 mci->mc_idx, top_layer, mid_layer, low_layer,
1225 PAGES_TO_MiB(page_frame_number) | offset_in_page,
1226 grain_bits, syndrome, other_detail);
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001227
1228 /* Memory type dependent details about the error */
1229 if (type == HW_EVENT_ERR_CORRECTED) {
1230 snprintf(detail, sizeof(detail),
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -03001231 "page:0x%lx offset:0x%lx grain:%ld syndrome:0x%lx",
Douglas Thompson052dfb42007-07-19 01:50:13 -07001232 page_frame_number, offset_in_page,
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001233 grain, syndrome);
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -03001234 edac_ce_error(mci, error_count, pos, msg, location, label,
1235 detail, other_detail, enable_per_layer_report,
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001236 page_frame_number, offset_in_page, grain);
1237 } else {
1238 snprintf(detail, sizeof(detail),
Mauro Carvalho Chehab53f2d022012-02-23 08:10:34 -03001239 "page:0x%lx offset:0x%lx grain:%ld",
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001240 page_frame_number, offset_in_page, grain);
Alan Coxda9bb1d2006-01-18 17:44:13 -08001241
Mauro Carvalho Chehab9eb07a72012-06-04 13:27:43 -03001242 edac_ue_error(mci, error_count, pos, msg, location, label,
1243 detail, other_detail, enable_per_layer_report);
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001244 }
Alan Coxda9bb1d2006-01-18 17:44:13 -08001245}
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -03001246EXPORT_SYMBOL_GPL(edac_mc_handle_error);