edac_mc.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  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_with_groups: Insert the 'mci' structure into the mci
  614. * global list and create sysfs entries associated with mci structure
  615. * @mci: pointer to the mci structure to be added to the list
  616. * @groups: optional attribute groups for the driver-specific sysfs entries
  617. *
  618. * Return:
  619. * 0 Success
  620. * !0 Failure
  621. */
  622. /* FIXME - should a warning be printed if no error detection? correction? */
  623. int edac_mc_add_mc_with_groups(struct mem_ctl_info *mci,
  624. const struct attribute_group **groups)
  625. {
  626. int ret = -EINVAL;
  627. edac_dbg(0, "\n");
  628. if (mci->mc_idx >= EDAC_MAX_MCS) {
  629. pr_warn_once("Too many memory controllers: %d\n", mci->mc_idx);
  630. return -ENODEV;
  631. }
  632. #ifdef CONFIG_EDAC_DEBUG
  633. if (edac_debug_level >= 3)
  634. edac_mc_dump_mci(mci);
  635. if (edac_debug_level >= 4) {
  636. int i;
  637. for (i = 0; i < mci->nr_csrows; i++) {
  638. struct csrow_info *csrow = mci->csrows[i];
  639. u32 nr_pages = 0;
  640. int j;
  641. for (j = 0; j < csrow->nr_channels; j++)
  642. nr_pages += csrow->channels[j]->dimm->nr_pages;
  643. if (!nr_pages)
  644. continue;
  645. edac_mc_dump_csrow(csrow);
  646. for (j = 0; j < csrow->nr_channels; j++)
  647. if (csrow->channels[j]->dimm->nr_pages)
  648. edac_mc_dump_channel(csrow->channels[j]);
  649. }
  650. for (i = 0; i < mci->tot_dimms; i++)
  651. if (mci->dimms[i]->nr_pages)
  652. edac_mc_dump_dimm(mci->dimms[i], i);
  653. }
  654. #endif
  655. mutex_lock(&mem_ctls_mutex);
  656. if (edac_mc_owner && edac_mc_owner != mci->mod_name) {
  657. ret = -EPERM;
  658. goto fail0;
  659. }
  660. if (add_mc_to_global_list(mci))
  661. goto fail0;
  662. /* set load time so that error rate can be tracked */
  663. mci->start_time = jiffies;
  664. mci->bus = &mc_bus[mci->mc_idx];
  665. if (edac_create_sysfs_mci_device(mci, groups)) {
  666. edac_mc_printk(mci, KERN_WARNING,
  667. "failed to create sysfs device\n");
  668. goto fail1;
  669. }
  670. /* If there IS a check routine, then we are running POLLED */
  671. if (mci->edac_check != NULL) {
  672. /* This instance is NOW RUNNING */
  673. mci->op_state = OP_RUNNING_POLL;
  674. edac_mc_workq_setup(mci, edac_mc_get_poll_msec(), true);
  675. } else {
  676. mci->op_state = OP_RUNNING_INTERRUPT;
  677. }
  678. /* Report action taken */
  679. edac_mc_printk(mci, KERN_INFO,
  680. "Giving out device to module %s controller %s: DEV %s (%s)\n",
  681. mci->mod_name, mci->ctl_name, mci->dev_name,
  682. edac_op_state_to_string(mci->op_state));
  683. edac_mc_owner = mci->mod_name;
  684. mutex_unlock(&mem_ctls_mutex);
  685. return 0;
  686. fail1:
  687. del_mc_from_global_list(mci);
  688. fail0:
  689. mutex_unlock(&mem_ctls_mutex);
  690. return ret;
  691. }
  692. EXPORT_SYMBOL_GPL(edac_mc_add_mc_with_groups);
  693. /**
  694. * edac_mc_del_mc: Remove sysfs entries for specified mci structure and
  695. * remove mci structure from global list
  696. * @pdev: Pointer to 'struct device' representing mci structure to remove.
  697. *
  698. * Return pointer to removed mci structure, or NULL if device not found.
  699. */
  700. struct mem_ctl_info *edac_mc_del_mc(struct device *dev)
  701. {
  702. struct mem_ctl_info *mci;
  703. edac_dbg(0, "\n");
  704. mutex_lock(&mem_ctls_mutex);
  705. /* find the requested mci struct in the global list */
  706. mci = find_mci_by_dev(dev);
  707. if (mci == NULL) {
  708. mutex_unlock(&mem_ctls_mutex);
  709. return NULL;
  710. }
  711. if (!del_mc_from_global_list(mci))
  712. edac_mc_owner = NULL;
  713. mutex_unlock(&mem_ctls_mutex);
  714. /* flush workq processes */
  715. edac_mc_workq_teardown(mci);
  716. /* marking MCI offline */
  717. mci->op_state = OP_OFFLINE;
  718. /* remove from sysfs */
  719. edac_remove_sysfs_mci_device(mci);
  720. edac_printk(KERN_INFO, EDAC_MC,
  721. "Removed device %d for %s %s: DEV %s\n", mci->mc_idx,
  722. mci->mod_name, mci->ctl_name, edac_dev_name(mci));
  723. return mci;
  724. }
  725. EXPORT_SYMBOL_GPL(edac_mc_del_mc);
  726. static void edac_mc_scrub_block(unsigned long page, unsigned long offset,
  727. u32 size)
  728. {
  729. struct page *pg;
  730. void *virt_addr;
  731. unsigned long flags = 0;
  732. edac_dbg(3, "\n");
  733. /* ECC error page was not in our memory. Ignore it. */
  734. if (!pfn_valid(page))
  735. return;
  736. /* Find the actual page structure then map it and fix */
  737. pg = pfn_to_page(page);
  738. if (PageHighMem(pg))
  739. local_irq_save(flags);
  740. virt_addr = kmap_atomic(pg);
  741. /* Perform architecture specific atomic scrub operation */
  742. atomic_scrub(virt_addr + offset, size);
  743. /* Unmap and complete */
  744. kunmap_atomic(virt_addr);
  745. if (PageHighMem(pg))
  746. local_irq_restore(flags);
  747. }
  748. /* FIXME - should return -1 */
  749. int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci, unsigned long page)
  750. {
  751. struct csrow_info **csrows = mci->csrows;
  752. int row, i, j, n;
  753. edac_dbg(1, "MC%d: 0x%lx\n", mci->mc_idx, page);
  754. row = -1;
  755. for (i = 0; i < mci->nr_csrows; i++) {
  756. struct csrow_info *csrow = csrows[i];
  757. n = 0;
  758. for (j = 0; j < csrow->nr_channels; j++) {
  759. struct dimm_info *dimm = csrow->channels[j]->dimm;
  760. n += dimm->nr_pages;
  761. }
  762. if (n == 0)
  763. continue;
  764. edac_dbg(3, "MC%d: first(0x%lx) page(0x%lx) last(0x%lx) mask(0x%lx)\n",
  765. mci->mc_idx,
  766. csrow->first_page, page, csrow->last_page,
  767. csrow->page_mask);
  768. if ((page >= csrow->first_page) &&
  769. (page <= csrow->last_page) &&
  770. ((page & csrow->page_mask) ==
  771. (csrow->first_page & csrow->page_mask))) {
  772. row = i;
  773. break;
  774. }
  775. }
  776. if (row == -1)
  777. edac_mc_printk(mci, KERN_ERR,
  778. "could not look up page error address %lx\n",
  779. (unsigned long)page);
  780. return row;
  781. }
  782. EXPORT_SYMBOL_GPL(edac_mc_find_csrow_by_page);
  783. const char *edac_layer_name[] = {
  784. [EDAC_MC_LAYER_BRANCH] = "branch",
  785. [EDAC_MC_LAYER_CHANNEL] = "channel",
  786. [EDAC_MC_LAYER_SLOT] = "slot",
  787. [EDAC_MC_LAYER_CHIP_SELECT] = "csrow",
  788. [EDAC_MC_LAYER_ALL_MEM] = "memory",
  789. };
  790. EXPORT_SYMBOL_GPL(edac_layer_name);
  791. static void edac_inc_ce_error(struct mem_ctl_info *mci,
  792. bool enable_per_layer_report,
  793. const int pos[EDAC_MAX_LAYERS],
  794. const u16 count)
  795. {
  796. int i, index = 0;
  797. mci->ce_mc += count;
  798. if (!enable_per_layer_report) {
  799. mci->ce_noinfo_count += count;
  800. return;
  801. }
  802. for (i = 0; i < mci->n_layers; i++) {
  803. if (pos[i] < 0)
  804. break;
  805. index += pos[i];
  806. mci->ce_per_layer[i][index] += count;
  807. if (i < mci->n_layers - 1)
  808. index *= mci->layers[i + 1].size;
  809. }
  810. }
  811. static void edac_inc_ue_error(struct mem_ctl_info *mci,
  812. bool enable_per_layer_report,
  813. const int pos[EDAC_MAX_LAYERS],
  814. const u16 count)
  815. {
  816. int i, index = 0;
  817. mci->ue_mc += count;
  818. if (!enable_per_layer_report) {
  819. mci->ce_noinfo_count += count;
  820. return;
  821. }
  822. for (i = 0; i < mci->n_layers; i++) {
  823. if (pos[i] < 0)
  824. break;
  825. index += pos[i];
  826. mci->ue_per_layer[i][index] += count;
  827. if (i < mci->n_layers - 1)
  828. index *= mci->layers[i + 1].size;
  829. }
  830. }
  831. static void edac_ce_error(struct mem_ctl_info *mci,
  832. const u16 error_count,
  833. const int pos[EDAC_MAX_LAYERS],
  834. const char *msg,
  835. const char *location,
  836. const char *label,
  837. const char *detail,
  838. const char *other_detail,
  839. const bool enable_per_layer_report,
  840. const unsigned long page_frame_number,
  841. const unsigned long offset_in_page,
  842. long grain)
  843. {
  844. unsigned long remapped_page;
  845. char *msg_aux = "";
  846. if (*msg)
  847. msg_aux = " ";
  848. if (edac_mc_get_log_ce()) {
  849. if (other_detail && *other_detail)
  850. edac_mc_printk(mci, KERN_WARNING,
  851. "%d CE %s%son %s (%s %s - %s)\n",
  852. error_count, msg, msg_aux, label,
  853. location, detail, other_detail);
  854. else
  855. edac_mc_printk(mci, KERN_WARNING,
  856. "%d CE %s%son %s (%s %s)\n",
  857. error_count, msg, msg_aux, label,
  858. location, detail);
  859. }
  860. edac_inc_ce_error(mci, enable_per_layer_report, pos, error_count);
  861. if (mci->scrub_mode == SCRUB_SW_SRC) {
  862. /*
  863. * Some memory controllers (called MCs below) can remap
  864. * memory so that it is still available at a different
  865. * address when PCI devices map into memory.
  866. * MC's that can't do this, lose the memory where PCI
  867. * devices are mapped. This mapping is MC-dependent
  868. * and so we call back into the MC driver for it to
  869. * map the MC page to a physical (CPU) page which can
  870. * then be mapped to a virtual page - which can then
  871. * be scrubbed.
  872. */
  873. remapped_page = mci->ctl_page_to_phys ?
  874. mci->ctl_page_to_phys(mci, page_frame_number) :
  875. page_frame_number;
  876. edac_mc_scrub_block(remapped_page,
  877. offset_in_page, grain);
  878. }
  879. }
  880. static void edac_ue_error(struct mem_ctl_info *mci,
  881. const u16 error_count,
  882. const int pos[EDAC_MAX_LAYERS],
  883. const char *msg,
  884. const char *location,
  885. const char *label,
  886. const char *detail,
  887. const char *other_detail,
  888. const bool enable_per_layer_report)
  889. {
  890. char *msg_aux = "";
  891. if (*msg)
  892. msg_aux = " ";
  893. if (edac_mc_get_log_ue()) {
  894. if (other_detail && *other_detail)
  895. edac_mc_printk(mci, KERN_WARNING,
  896. "%d UE %s%son %s (%s %s - %s)\n",
  897. error_count, msg, msg_aux, label,
  898. location, detail, other_detail);
  899. else
  900. edac_mc_printk(mci, KERN_WARNING,
  901. "%d UE %s%son %s (%s %s)\n",
  902. error_count, msg, msg_aux, label,
  903. location, detail);
  904. }
  905. if (edac_mc_get_panic_on_ue()) {
  906. if (other_detail && *other_detail)
  907. panic("UE %s%son %s (%s%s - %s)\n",
  908. msg, msg_aux, label, location, detail, other_detail);
  909. else
  910. panic("UE %s%son %s (%s%s)\n",
  911. msg, msg_aux, label, location, detail);
  912. }
  913. edac_inc_ue_error(mci, enable_per_layer_report, pos, error_count);
  914. }
  915. /**
  916. * edac_raw_mc_handle_error - reports a memory event to userspace without doing
  917. * anything to discover the error location
  918. *
  919. * @type: severity of the error (CE/UE/Fatal)
  920. * @mci: a struct mem_ctl_info pointer
  921. * @e: error description
  922. *
  923. * This raw function is used internally by edac_mc_handle_error(). It should
  924. * only be called directly when the hardware error come directly from BIOS,
  925. * like in the case of APEI GHES driver.
  926. */
  927. void edac_raw_mc_handle_error(const enum hw_event_mc_err_type type,
  928. struct mem_ctl_info *mci,
  929. struct edac_raw_error_desc *e)
  930. {
  931. char detail[80];
  932. int pos[EDAC_MAX_LAYERS] = { e->top_layer, e->mid_layer, e->low_layer };
  933. /* Memory type dependent details about the error */
  934. if (type == HW_EVENT_ERR_CORRECTED) {
  935. snprintf(detail, sizeof(detail),
  936. "page:0x%lx offset:0x%lx grain:%ld syndrome:0x%lx",
  937. e->page_frame_number, e->offset_in_page,
  938. e->grain, e->syndrome);
  939. edac_ce_error(mci, e->error_count, pos, e->msg, e->location, e->label,
  940. detail, e->other_detail, e->enable_per_layer_report,
  941. e->page_frame_number, e->offset_in_page, e->grain);
  942. } else {
  943. snprintf(detail, sizeof(detail),
  944. "page:0x%lx offset:0x%lx grain:%ld",
  945. e->page_frame_number, e->offset_in_page, e->grain);
  946. edac_ue_error(mci, e->error_count, pos, e->msg, e->location, e->label,
  947. detail, e->other_detail, e->enable_per_layer_report);
  948. }
  949. }
  950. EXPORT_SYMBOL_GPL(edac_raw_mc_handle_error);
  951. /**
  952. * edac_mc_handle_error - reports a memory event to userspace
  953. *
  954. * @type: severity of the error (CE/UE/Fatal)
  955. * @mci: a struct mem_ctl_info pointer
  956. * @error_count: Number of errors of the same type
  957. * @page_frame_number: mem page where the error occurred
  958. * @offset_in_page: offset of the error inside the page
  959. * @syndrome: ECC syndrome
  960. * @top_layer: Memory layer[0] position
  961. * @mid_layer: Memory layer[1] position
  962. * @low_layer: Memory layer[2] position
  963. * @msg: Message meaningful to the end users that
  964. * explains the event
  965. * @other_detail: Technical details about the event that
  966. * may help hardware manufacturers and
  967. * EDAC developers to analyse the event
  968. */
  969. void edac_mc_handle_error(const enum hw_event_mc_err_type type,
  970. struct mem_ctl_info *mci,
  971. const u16 error_count,
  972. const unsigned long page_frame_number,
  973. const unsigned long offset_in_page,
  974. const unsigned long syndrome,
  975. const int top_layer,
  976. const int mid_layer,
  977. const int low_layer,
  978. const char *msg,
  979. const char *other_detail)
  980. {
  981. char *p;
  982. int row = -1, chan = -1;
  983. int pos[EDAC_MAX_LAYERS] = { top_layer, mid_layer, low_layer };
  984. int i, n_labels = 0;
  985. u8 grain_bits;
  986. struct edac_raw_error_desc *e = &mci->error_desc;
  987. edac_dbg(3, "MC%d\n", mci->mc_idx);
  988. /* Fills the error report buffer */
  989. memset(e, 0, sizeof (*e));
  990. e->error_count = error_count;
  991. e->top_layer = top_layer;
  992. e->mid_layer = mid_layer;
  993. e->low_layer = low_layer;
  994. e->page_frame_number = page_frame_number;
  995. e->offset_in_page = offset_in_page;
  996. e->syndrome = syndrome;
  997. e->msg = msg;
  998. e->other_detail = other_detail;
  999. /*
  1000. * Check if the event report is consistent and if the memory
  1001. * location is known. If it is known, enable_per_layer_report will be
  1002. * true, the DIMM(s) label info will be filled and the per-layer
  1003. * error counters will be incremented.
  1004. */
  1005. for (i = 0; i < mci->n_layers; i++) {
  1006. if (pos[i] >= (int)mci->layers[i].size) {
  1007. edac_mc_printk(mci, KERN_ERR,
  1008. "INTERNAL ERROR: %s value is out of range (%d >= %d)\n",
  1009. edac_layer_name[mci->layers[i].type],
  1010. pos[i], mci->layers[i].size);
  1011. /*
  1012. * Instead of just returning it, let's use what's
  1013. * known about the error. The increment routines and
  1014. * the DIMM filter logic will do the right thing by
  1015. * pointing the likely damaged DIMMs.
  1016. */
  1017. pos[i] = -1;
  1018. }
  1019. if (pos[i] >= 0)
  1020. e->enable_per_layer_report = true;
  1021. }
  1022. /*
  1023. * Get the dimm label/grain that applies to the match criteria.
  1024. * As the error algorithm may not be able to point to just one memory
  1025. * stick, the logic here will get all possible labels that could
  1026. * pottentially be affected by the error.
  1027. * On FB-DIMM memory controllers, for uncorrected errors, it is common
  1028. * to have only the MC channel and the MC dimm (also called "branch")
  1029. * but the channel is not known, as the memory is arranged in pairs,
  1030. * where each memory belongs to a separate channel within the same
  1031. * branch.
  1032. */
  1033. p = e->label;
  1034. *p = '\0';
  1035. for (i = 0; i < mci->tot_dimms; i++) {
  1036. struct dimm_info *dimm = mci->dimms[i];
  1037. if (top_layer >= 0 && top_layer != dimm->location[0])
  1038. continue;
  1039. if (mid_layer >= 0 && mid_layer != dimm->location[1])
  1040. continue;
  1041. if (low_layer >= 0 && low_layer != dimm->location[2])
  1042. continue;
  1043. /* get the max grain, over the error match range */
  1044. if (dimm->grain > e->grain)
  1045. e->grain = dimm->grain;
  1046. /*
  1047. * If the error is memory-controller wide, there's no need to
  1048. * seek for the affected DIMMs because the whole
  1049. * channel/memory controller/... may be affected.
  1050. * Also, don't show errors for empty DIMM slots.
  1051. */
  1052. if (e->enable_per_layer_report && dimm->nr_pages) {
  1053. if (n_labels >= EDAC_MAX_LABELS) {
  1054. e->enable_per_layer_report = false;
  1055. break;
  1056. }
  1057. n_labels++;
  1058. if (p != e->label) {
  1059. strcpy(p, OTHER_LABEL);
  1060. p += strlen(OTHER_LABEL);
  1061. }
  1062. strcpy(p, dimm->label);
  1063. p += strlen(p);
  1064. *p = '\0';
  1065. /*
  1066. * get csrow/channel of the DIMM, in order to allow
  1067. * incrementing the compat API counters
  1068. */
  1069. edac_dbg(4, "%s csrows map: (%d,%d)\n",
  1070. mci->csbased ? "rank" : "dimm",
  1071. dimm->csrow, dimm->cschannel);
  1072. if (row == -1)
  1073. row = dimm->csrow;
  1074. else if (row >= 0 && row != dimm->csrow)
  1075. row = -2;
  1076. if (chan == -1)
  1077. chan = dimm->cschannel;
  1078. else if (chan >= 0 && chan != dimm->cschannel)
  1079. chan = -2;
  1080. }
  1081. }
  1082. if (!e->enable_per_layer_report) {
  1083. strcpy(e->label, "any memory");
  1084. } else {
  1085. edac_dbg(4, "csrow/channel to increment: (%d,%d)\n", row, chan);
  1086. if (p == e->label)
  1087. strcpy(e->label, "unknown memory");
  1088. if (type == HW_EVENT_ERR_CORRECTED) {
  1089. if (row >= 0) {
  1090. mci->csrows[row]->ce_count += error_count;
  1091. if (chan >= 0)
  1092. mci->csrows[row]->channels[chan]->ce_count += error_count;
  1093. }
  1094. } else
  1095. if (row >= 0)
  1096. mci->csrows[row]->ue_count += error_count;
  1097. }
  1098. /* Fill the RAM location data */
  1099. p = e->location;
  1100. for (i = 0; i < mci->n_layers; i++) {
  1101. if (pos[i] < 0)
  1102. continue;
  1103. p += sprintf(p, "%s:%d ",
  1104. edac_layer_name[mci->layers[i].type],
  1105. pos[i]);
  1106. }
  1107. if (p > e->location)
  1108. *(p - 1) = '\0';
  1109. /* Report the error via the trace interface */
  1110. grain_bits = fls_long(e->grain) + 1;
  1111. trace_mc_event(type, e->msg, e->label, e->error_count,
  1112. mci->mc_idx, e->top_layer, e->mid_layer, e->low_layer,
  1113. PAGES_TO_MiB(e->page_frame_number) | e->offset_in_page,
  1114. grain_bits, e->syndrome, e->other_detail);
  1115. edac_raw_mc_handle_error(type, mci, e);
  1116. }
  1117. EXPORT_SYMBOL_GPL(edac_mc_handle_error);