edac_mc.c 34 KB

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